Fixing the request method.

data_sync
Pedro de Oliveira Guedes 2022-01-21 10:58:45 -03:00
parent f67bef6d43
commit 4c130636d3
1 changed files with 12 additions and 5 deletions

View File

@ -1,3 +1,4 @@
import base64
import json
import os
import requests
@ -35,12 +36,18 @@ class API_Proxy:
headers = {"X-API-KEY": apikey}
res = requests.post(url, json = object, headers = headers, verify = False)
if res.status_code >= 400:
raise Exception(f"HTTP ERROR: {str(res.status_code)} - {res.text}")
if res.headers.get("Content-Type") != None and res.headers.get("Content-Type").find("json") != -1:
return json.loads(res.text)
response = json.loads(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)
else:
return res.text
return decoded_body
def do (self, request: dict):
"""