Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Set-Cookie in header using requests module

Tags:

python

cookies

When I use PHP to get cookie, it returns:

session_id=abih14s7l4lgo3splta7f6bd14; cccaa78fa9e13785130119a4924db0f4=96637ae... (more)

But when I use Python, it returns:

session_id=abih14s7l4lgo3splta7f6bd14

... the rest of cookies is lost.

My code Python:

res_post = requests.post(LOGIN_URL, data = {mydata})
cookies = dict(res_post.cookies.items())
like image 778
overnight Avatar asked Sep 28 '26 06:09

overnight


1 Answers

Looks like you're using the requests library. The response.cookies is already a dictionary, so there's no need to cast it again.

You should access the cookies on the response like so:

response = requests.post(LOGIN_URL, data={mydata})
print response.cookies['session_id']

See here for more detail: http://docs.python-requests.org/en/latest/user/quickstart/#cookies

like image 66
dursk Avatar answered Sep 29 '26 19:09

dursk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!