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.
master
Pedro de Oliveira Guedes 2022-01-31 12:08:18 -03:00
parent 985ecd7e12
commit 94337e2949
1 changed files with 10 additions and 5 deletions

View File

@ -55,10 +55,8 @@ class API_Proxy:
if res.status_code >= 400: if res.status_code >= 400:
raise Exception(f"HTTP ERROR: {str(res.status_code)} - {res.text}") 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) return json.loads(res.text)
else:
return res.text
def do (self, request: dict): def do (self, request: dict):
@ -97,5 +95,12 @@ class API_Proxy:
-> Estrutura APIProxyResponse definida nesta classe. -> Estrutura APIProxyResponse 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