使用http.client访问接口
import http.client
import urllib.parse
import ssl
import json
header_data = {
"Host": "gank.io",
"Accept-Encoding": "gzip",
"User-Agent": "Android-ALI-Moblie 1.3.0",
"Content-Type": "application/json;charset=UTF-8",
"Connection": "Keep-Alive"
}
# test_data = urllib.parse.urlencode({
# "username": "aaa",
# "password": "123456",
# })
conn = http.client.HTTPSConnection("gank.io", context=ssl.SSLContext(ssl.PROTOCOL_SSLv23))
payload = ‘‘
conn.request("GET", "/api/v2/categories/GanHuo", payload, header_data)
resp = conn.getresponse()
result = resp.read()
jsonobj = json.loads(result)
print(jsonobj[‘status‘])
conn.close()
http.client