http request with cookie sending
Kent Johnson
kent at kentsjohnson.com
Wed Apr 19 08:34:19 EDT 2006
itay_k wrote:
> Hi,
>
> I want to send a cookie on some http request (with urllib2),
> so I created a Cookie but I cant associate it with CookieJar object.
You have to use a cookielib.Cookie, not Cookie.SimpleCookie():
import cookielib, urllib2
cj = cookielib.CookieJar()
cookie = cookielib.Cookie(...your cookie data here...)
cj.set_cookie(cookie)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
data = urllib2.urlopen(...).read()
Kent
More information about the Python-list
mailing list