Last active
August 30, 2018 14:06
-
-
Save fabianogoes/19d815063336bf01cbd248e23df217ef to your computer and use it in GitHub Desktop.
Example request POST by Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python3 | |
""" | |
requirements: | |
requests==2.19.1 | |
Reference: http://docs.python-requests.org/en/master/user/quickstart/ | |
""" | |
import requests | |
def request(list-dict): | |
try: | |
req_body = json.dumps(list-dict).encode() | |
autorization = "Basic {}".format(API_AUTH_HASH) | |
headers = { | |
'Authorization': autorization, | |
'Accept': 'application/json', | |
'Cache-Control': 'no-cache', | |
'Content-Type': 'application/json', | |
'Content-Length': str(len(req_body)) | |
} | |
response = requests.post(API_URL, data=req_body, headers=headers) | |
if response.status_code not in (200, 201): | |
print('Response status_code: {}'.format(response.status_code)) | |
except Exception as e: | |
print('Request Error: {}'.format(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment