Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python requests - saving cookie for later url usage

I been trying to get a cookie and post it to a url in later use in the program, but I cant seem to get the cookie parameters to work.

Right now I have

response = requests.get("url")

But how exactly do I retrive cookies from this url and post them to a new url (the same cookies). The tutorial in requests is somewhat vague on the topic and gives examples I cannot test. Hope someone can help with further examples.

This is python 2.7 btw.

like image 702
PythonRocks Avatar asked Sep 27 '12 15:09

PythonRocks


1 Answers

You want to use a session:

s = requests.session()

response = s.get('url')

You use the session just like the requests module (it has the same methods), but it'll retain cookies for you and send them along on future requests.

like image 165
Martijn Pieters Avatar answered Sep 27 '22 21:09

Martijn Pieters