From 9fe25d052e4003372d3e2babd177e73886c7ae41 Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Mon, 31 Jan 2022 08:54:33 -0300 Subject: [PATCH] Standardizing the request method. --- api/apiproxy/cli.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/api/apiproxy/cli.py b/api/apiproxy/cli.py index 4d971ac..8fa0cdd 100644 --- a/api/apiproxy/cli.py +++ b/api/apiproxy/cli.py @@ -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): """