send cookie on request with urllib2

John J. Lee jjl at pobox.com
Thu Apr 20 18:20:31 EDT 2006


Kent Johnson <kent at kentsjohnson.com> writes:

> itay_k wrote:
> > Hi,
> > 
> > I dont understand why this is so complicated, just to add one line of
> > cookie header on the GET request.
> > 
> > This is my unworking code:
> > import time
> > import Cookie
> > import cookielib, urllib2
> > 
> > c= cookielib.Cookie(1,"Name","Tom", 80,False, "itay", False, False,
> > "d:\\asddd",False, False,time.time()+1000,False,None,None,None)
> 
>     ^^^^ path is the server path to which the cookie applies. Try '/'.

"""
"No," scolded Yoda. "Do, or do not. There is no try."
"""

(there, a Star Wars quote -- I guess there's truly no hope of ever
erasing my geek status now!-)

Why guess?  Why not log in (using Python) and see what the cookie
actually is?  Once you've actually done that, there's nothing to stop
you storing it as a Cookie constructor call.

I know I certainly don't remember all the *truly horrendous* detail of
what *exactly* all those parameters mean :-)  The Cookie object, as is
documented, is merely a struct object and it is easy to construct
incorrect and even self-inconsistent Cookie objects; CookieJar has all
the knowledge about constructing cookies -- and allows use of that
knowledge through .make_cookies() and .load()/.revert().


John




More information about the Python-list mailing list