import json
import requests
def call_api_web_server(req_type, req_data):
headers = {
"Accept": "application/json, text/plain, */*",
"Accept-Language": "zh-CN,zh;q=0.9",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Type": "application/json;charset=UTF-8",
"Pragma": "no-cache",
}
api_url = "https://api.addcoder.com/" + req_type
req_params = {"api_auth_key": "601137664d318ffde7c095381db55434"}
response = requests.post(
api_url,
headers=headers,
params=req_params,
data=json.dumps(req_data, separators=(",", ":")),
timeout=20,
)
if response.json().get("respCode") == 0:
return response.json()["respData"]
else:
print(
"[api]-[error]-[%s]-[%s]"
% (response.json().get("respMsg"), response.json().get("error"))
)
if __name__ == "__main__":
respData = call_api_web_server("cdt_cookie", "")
cookie = respData["data"]
print(cookie)