fix api-client
This commit is contained in:
parent
a858809f06
commit
a3587f80a6
@ -15,15 +15,15 @@ def api_client(call_dict):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if method == 'GET':
|
if method == 'GET':
|
||||||
response = client.get(url, headers=headers, params=body)
|
response = client.get(url, headers=headers, params=body, verify=False)
|
||||||
elif method == 'POST':
|
elif method == 'POST':
|
||||||
response = client.post(url, headers=headers, json=body)
|
response = client.post(url, headers=headers, json=body, verify=False)
|
||||||
elif method == 'PUT':
|
elif method == 'PUT':
|
||||||
response = client.put(url, headers=headers, json=body)
|
response = client.put(url, headers=headers, json=body, verify=False)
|
||||||
elif method == 'OPTIONS':
|
elif method == 'OPTIONS':
|
||||||
response = client.options(url, headers=headers, json=body)
|
response = client.options(url, headers=headers, json=body, verify=False)
|
||||||
elif method == 'DELETE':
|
elif method == 'DELETE':
|
||||||
response = client.delete(url)
|
response = client.delete(url, verify=False)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid method: {method}")
|
raise ValueError(f"Invalid method: {method}")
|
||||||
|
|
||||||
@ -32,4 +32,8 @@ def api_client(call_dict):
|
|||||||
print(f"Error details: {str(e)}", file=sys.stderr)
|
print(f"Error details: {str(e)}", file=sys.stderr)
|
||||||
exit(e.response.status_code)
|
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
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
from config import get_cfg
|
from config import get_cfg
|
||||||
from client import api_client
|
from client import api_client
|
||||||
from oauth_helper import get_legacy_token
|
from oauth_helper import get_legacy_token
|
||||||
@ -12,10 +14,10 @@ if __name__ == "__main__":
|
|||||||
api_call = {
|
api_call = {
|
||||||
"token": token,
|
"token": token,
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"url": cfg["api_url"] + '/data-delivery/sarredaction/119',
|
"url": cfg["api_url"] + '/data-delivery/role',
|
||||||
"headers": {'Content-Type': 'application/json'},
|
"headers": {'Content-Type': 'application/json'},
|
||||||
"body": {}
|
"body": {"application_id": 1}
|
||||||
}
|
}
|
||||||
|
|
||||||
api_response = api_client(api_call)
|
api_response = api_client(api_call)
|
||||||
print(api_response)
|
print(json.dumps(api_response, indent=4))
|
||||||
|
Loading…
Reference in New Issue
Block a user