Skip to content

Instantly share code, notes, and snippets.

@afaqk9394
Created November 3, 2019 06:08
Show Gist options
  • Select an option

  • Save afaqk9394/9aff6f69d7701b5c811dadf089343843 to your computer and use it in GitHub Desktop.

Select an option

Save afaqk9394/9aff6f69d7701b5c811dadf089343843 to your computer and use it in GitHub Desktop.
API authentication mechanisms
import requests
import json
token = 'B3h5OJYadMUFBYqhxkX6XOozRBI4RJSZlsB3' #wrong token supplied
url = 'https://gorest.co.in/public-api/users'
data = {"email":"email8@example.com","first_name":"devnet","last_name":"associate","gender":"male"}
result = requests.post(url,
headers={'Content-Type':'application/json',
'Authorization': 'Bearer {}'.format(token)},data=json.dumps(data))
print('Code: ', result.status_code)
print('Content: ', result.content.decode()[:500] + '...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment