Question

i am using python-requests on python 2.7, i am trying to authenticate against a web-server that returns multiple set-cookie headers in the response. python-requests keeps only one of those cookies.

i couldn't find a python 'http' client that either handles this problem correctly, or allows access to the raw header with the 'set-cookie' statements in order to manually deal with the problem.

i found a few statements in the internet that claim that this problem was solved in python3, however no further details or examples were provided.

would appreciate any assistance.

thanks

Was it helpful?

Solution

It is possible to get the Set-Cookie-Header with requests.

import requests
r = requests.get("http://localhost:5000")  
# a flask application there sets two cookies 'first' and 'second'

r.cookies.keys()
# returns ['first', 'second']

r.headers['Set-Cookie']
# returns 'first=4; Path=/, second=42; Path=/'

Please show some code of what you did to see why it didn't work for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top