Standardizing the request method.
parent
ff5d9b9cf2
commit
9fe25d052e
|
@ -36,18 +36,14 @@ class API_Proxy:
|
|||
headers = {"X-API-KEY": apikey}
|
||||
res = requests.post(url, json = object, headers = headers, verify = False)
|
||||
|
||||
response = json.loads(res.text)
|
||||
if res.status_code >= 400:
|
||||
raise Exception(f"HTTP ERROR: {str(res.status_code)} - {res.text}")
|
||||
|
||||
byte_encoded_body = base64.b64decode(response['body'])
|
||||
decoded_body = str(byte_encoded_body, "utf-8")
|
||||
|
||||
if response['status_code'] >= 400:
|
||||
raise Exception(f"HTTP ERROR: {str(response['status_code'])} - {response['body']}")
|
||||
|
||||
if response['header']['Content-Type'] != None and response['header']['Content-Type'].find('json') != -1:
|
||||
return json.loads(decoded_body)
|
||||
if res.headers.get("Content-Type") != None and res.headers.get("Content-Type").find("json") != -1:
|
||||
return json.loads(res.text)
|
||||
else:
|
||||
return decoded_body
|
||||
return res.text
|
||||
|
||||
|
||||
def do (self, request: dict):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue