urlib - automatic cookie handling

Michael Geary Mike at DeleteThis.Geary.com
Tue Jun 29 10:29:02 EDT 2004


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





More information about the Python-list mailing list