PythonRocks
PythonRocks

Reputation: 59

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.

Upvotes: 5

Views: 5244

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121744

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.

Upvotes: 15

Related Questions