From 94337e294968d4524824ac84600b963fbba1ab6a Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Mon, 31 Jan 2022 12:08:18 -0300 Subject: [PATCH] Changing json request return type, now it only returns dictionaries; Changing the do method return interface. Now, instead of returning only the response body, it returns the entire response. --- api/apiproxy/cli.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/api/apiproxy/cli.py b/api/apiproxy/cli.py index c5a1a1d..2c53ac9 100644 --- a/api/apiproxy/cli.py +++ b/api/apiproxy/cli.py @@ -55,10 +55,8 @@ class API_Proxy: 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) - else: - return res.text + + return json.loads(res.text) def do (self, request: dict): @@ -97,5 +95,12 @@ class API_Proxy: -> Estrutura APIProxyResponse já definida nesta classe. """ - return self.__request_json_post__ ("/ipc/apiproxy/do", request) + do_response = self.__request_json_post__ ("/ipc/apiproxy/do", request) + + do_response["body"] = base64.b64decode(do_response["body"]) + do_response["body"] = str(do_response["body"], "utf-8") + if do_response["header"]["Content-Type"].find("json") != -1: + do_response["body"] = json.loads(do_response["body"]) + + return do_response