import requests
session = requests.Session()
url = 'https://httpbin.org/headers'
access_token = {
'Authorization': 'Bearer {access_token}'
}
session.headers.update(access_token)
response1 = session.get(url)
response2 = session.get(url)
print('response1: ', response1.json()['headers']['Authorization'])
print('response2: ', response2.json()['headers']['Authorization'])
s = requests.Session()
s.auth = ('user', 'pass')
s.headers.update({'x-test': 'true'})
# both 'x-test' and 'x-test2' are sent
s.get('https://httpbin.org/headers', headers={'x-test2': 'true'})
with requests.Session() as s:
s.get('https://httpbin.org/cookies/set/sessioncookie/123456789')
s = requests.Session()
s.get('https://httpbin.org/cookies/set/sessioncookie/123456789')
r = s.get('https://httpbin.org/cookies')
print(r.text)
# '{"cookies": {"sessioncookie": "123456789"}}'
# Creating a Session in python using requests
>>> from requests_html import HTMLSession
>>> session = HTMLSession()
>>> r = session.get('https://python.org/')