From a3587f80a6a1dd864d1535a647fbedb5ada83f05 Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Sat, 20 Jul 2024 00:54:31 +0100 Subject: [PATCH] fix api-client --- api-client/client.py | 16 ++++++++++------ api-client/main.py | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/api-client/client.py b/api-client/client.py index 9f214ac..7b771ca 100644 --- a/api-client/client.py +++ b/api-client/client.py @@ -15,15 +15,15 @@ def api_client(call_dict): try: if method == 'GET': - response = client.get(url, headers=headers, params=body) + response = client.get(url, headers=headers, params=body, verify=False) elif method == 'POST': - response = client.post(url, headers=headers, json=body) + response = client.post(url, headers=headers, json=body, verify=False) elif method == 'PUT': - response = client.put(url, headers=headers, json=body) + response = client.put(url, headers=headers, json=body, verify=False) elif method == 'OPTIONS': - response = client.options(url, headers=headers, json=body) + response = client.options(url, headers=headers, json=body, verify=False) elif method == 'DELETE': - response = client.delete(url) + response = client.delete(url, verify=False) else: raise ValueError(f"Invalid method: {method}") @@ -32,4 +32,8 @@ def api_client(call_dict): print(f"Error details: {str(e)}", file=sys.stderr) exit(e.response.status_code) - return response.content, response.status_code + if response.status_code == 200: + return response.json() + else: + return response.status_code, response.reason + diff --git a/api-client/main.py b/api-client/main.py index 0a61578..d4f4422 100644 --- a/api-client/main.py +++ b/api-client/main.py @@ -1,3 +1,5 @@ +import json + from config import get_cfg from client import api_client from oauth_helper import get_legacy_token @@ -12,10 +14,10 @@ if __name__ == "__main__": api_call = { "token": token, "method": "GET", - "url": cfg["api_url"] + '/data-delivery/sarredaction/119', + "url": cfg["api_url"] + '/data-delivery/role', "headers": {'Content-Type': 'application/json'}, - "body": {} + "body": {"application_id": 1} } api_response = api_client(api_call) - print(api_response) + print(json.dumps(api_response, indent=4))