urlib - automatic cookie handling

Alex Hunsley lard at tardis.ed.ac.molar.uk
Tue Jun 29 10:30:32 EDT 2004


Michael Geary wrote:

> Alex Hunsley wrote:
> 
>>I'm using urllib to post data to a web form by issuing a command similar
>>to this:
>>
>>filename, headers =
>>
> 
> urllib.urlretrieve("http://www.thewebsitenamehere.com/servlet/com.blah.bloo.
> XmlFeed",
> 
>>"content.txt", None, urllib.urlencode({"aParameter": "theValue"}))
>>
>>Now, the problem is that the above fails, since I am not sending a session
>>cookie. Visitors to the web sites' html submission form are sent a session
>>cookie which is given back to the server when they submit a search via the
>>browser, as often happens.
>>Now, I could use urllib to get the form page and read the cookie from the
>>headers that are returned and then manually put that cookie in my
>>submission to the servlet, but my question is: is there a way to tell
> 
> urllib
> 
>>or some other part of HTTP handling in python that I want to remember
>>any cookie that is given to me, and give it back to that site if I send
>>requests later on?
> 
> 
> You're looking for ClientCookie:
> 
> http://wwwsearch.sourceforge.net/ClientCookie/
> 
> http://wwwsearch.sourceforge.net/ClientCookie/doc.html
> 
> -Mike

hi there!
Snap! I think we both posted at about the same time. Good to know someone was 
suggesting it anyway!

thanks
alex






More information about the Python-list mailing list