fix api-client

This commit is contained in:
Greg Gauthier 2024-07-20 00:54:31 +01:00
parent a858809f06
commit a3587f80a6
2 changed files with 15 additions and 9 deletions

View File

@ -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

View File

@ -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))