티스토리 뷰

Language/Python

python3 ssl인증 Basic통과 하기

KyeongRok Kim 2019. 10. 15. 16:01

ssl Basic인증 통과하기

import http.client, json, ssl, base64

def convertByteToGiga(byte):
    return byte / 1024 / 1024 / 1024

def getApiResponse(query):
    auth = str.encode("%s:%s" % ('root', ''))
    user_and_pass = base64.b64encode(auth).decode("ascii")
    headers = {"Authorization":"Basic {}".format(user_and_pass),
               "Accept":"application/json"}
    conn = http.client.HTTPSConnection('0.0.0.0', 8080, context=ssl._create_unverified_context())
    conn.request("GET", query, headers=headers)
    res = conn.getresponse()
    return res

#res = getApiResponse("/platform/1/statistics/current?key=node.sysfs.root.bytes.used")
#res = getApiResponse("/platform/1/statistics/current?key=node.sysfs.var.percent.free")
res = getApiResponse("/platform/5/statistics/current?key=cluster.alert.info")
data = res.read()
result = json.loads(data.decode('utf-8'))

 

authentication authorization

인증, 권한부여

 

end

728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함