How to keep cookies when making http requests (Python 2.7)

Luca Cerone luca.cerone at gmail.com
Wed Aug 21 04:18:28 EDT 2013


> 
> I have used "cookielib" externally to "urllib2". It looks
> 
> like this:
> 
> from urllib2 import urlopen, Request
> 
> from cookielib import CookieJar
> cookies = CookieJar()
> 
> ....
> 
> r = Request(...)
> 
> cookies.add_cookie_header(r) # set the cookies
> 
> R = urlopen(r, ...) # make the request
> 
> cookies.extract_cookies(R, r) # remember the new cookies

Hi Dieter,
thanks a lot for the help.
I am sorry but your code is not very clear to me.
It seems that you are setting some cookies,
but I can't understand how you use the ones that the site
sends to you when you perform the initial request.

Have you tried this code to check if this work?
If it works as intended can you explain a bit better
what it does exactly?

Thanks again!
Luca



More information about the Python-list mailing list