Extreme API with Python

Table Of Contents
Extreme API with Python
Page | 11
Part no.9036931-00 Rev AA February 2021
2.2.4.4 X-Auth-Token
The X-Auth-Token is an unregistered header and is not subject to formal specification. Its presence and
content are always tied to a respective application. It typically stores a token for authorization and can
be considered as a shortcut of the bearer token defined in OAuth 2.0.
For Extreme APIs, the X-Auth-Token will be used with EXOS and VOSS Restconf implementation.
2.2.5 Manipulating Headers with Python
The requests module, and by extension the Urllib module, provide easy access to HTTP Headers. From
requests, headers are simply a Python dictionary, and you can manipulate both the request and
response headers.
import requests
r = requests.get("HTTPS://api.nasa.gov/planetary/apod")
print("Headers sent: ", r.request.headers)
print("\nHeaders received: ", r.headers)
The result is shown below:
C:\Extreme API with Python> headers-example.py
Headers sent: {'User-Agent': 'python-requests/2.22.0', 'Accept-Encoding':
'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}
Headers received: {'Server': 'openresty', 'Date': 'Sun, 14 Jun 2020 14:55:49
GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked',
'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'Access-Control-Allow-
Origin': '*', 'X-Cache': 'MISS', 'Strict-Transport-Security': 'max-
age=31536000; preload', 'Content-Encoding': 'gzip'}
You can easily customize headers using the requests module:
import requests
headers = {
'content-type': 'application/json',
'x-auth-token': 'c3RlZjpleHRyZW1l'
}
r = requests.get("HTTPS://httpbin.org/get", headers=headers)
print("Headers sent: ", r.request.headers)
print("\nHeaders received: ", r.headers)