headers not stored inside the session this way.
You need to either explicitly pass them each time you make a request, or install s.headers once:
with requests.Session() as s: s.headers = {'User-Agent': 'Mozilla/5.0'}
You can verify that the correct headers were sent using the response.request.headers check:
with requests.Session() as s: s.headers = {'User-Agent': 'Mozilla/5.0'} r = s.post(api_url, data=json.dumps(logindata)) print(r.request.headers)
Also look at how the Session class is implemented - each time you make a request it combines request.headers with the headers that you set for the session object:
headers=merge_setting(request.headers, self.headers, dict_class=CaseInsensitiveDict),
source share