Standardizing the request method.

master
Pedro de Oliveira Guedes 2022-01-31 08:54:33 -03:00
parent ff5d9b9cf2
commit 9fe25d052e
1 changed files with 6 additions and 10 deletions

View File

@ -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):
"""