POST with basic auth and cookie from python?

Michael Foord fuzzyman at
Sat Sep 4 20:20:27 CEST 2004

Lee Harr <missive at> wrote in message news:<slrncjjdlh.f6.missive at homer.localdomain>...
> On 2004-09-04, Michael Foord <fuzzyman at> wrote:
> > Dan Stromberg <strombrg at> wrote in message news:<pan.2004. at>...
> >> If I wanted to write a python script that performs basic auth, gets a
> >> cookie, and then does an http POST using the cookie for authentication,
> >> what would be the best python API to write to?
> >> 
> >> Does someone already have example code that does something like this?
> >> 
> > Oh - if anyone can help on this it would be great !! What the heck is
> > a realm and how do they work !!
> >
> >
> Not sure if this helps ...

Thanks - it was the comments from that recipe that I got the code to
do basic athorization. One of the commenters also states that using
urllib2.HTTPPasswordMgrWithDefaultRealm will also do the job
(remembering the username and password for the realm, once you have
supplied it). The trouble is that in *my* code (sorry to the original
poster for hijacking the thread) is a CGI. This means that for each
seperate page access the process starts afresh - so I would need to
save in an external file the username and password combinations...
which is by no means an ideal solution.

The bottom line for me is that I don't actually understand what a
realm is and how http does authentication beyond the first page access
- does it need the username and password encoded in the headers for
access to every page in that realm ?

Tell you what - I'll start another thread and see if anyone



More information about the Python-list mailing list