[Tutor] Digest Authentication with URLLIB2

Erik Price eprice@ptc.com
Wed Feb 12 15:49:02 2003


aschmidt@fredericksburg.com wrote:
> I need some examples of how to incorporate digest authentication into a Python script. Right now, I use urllib to handle the passing of the url and the return of the data...a huge block of tab delimited data.
> 
> But the group where I get the data is changing their access methods and say they will be requiring digest authentication before being able to call that url now.
> 
> Any ideas or examples, or links and pointers to such things elsewhere is much appreciated.

I SFTW'd and found this nice, simple explanation of what digest 
authentication is:

   http://frontier.userland.com/stories/storyReader$2159

And then I found mention of digest authentication in the documentation 
of the urllib2 module:

   http://www.python.org/doc/current/lib/module-urllib2.html

I didn't try it (no time, have my own project I'm working on), but it 
looks like what you're supposed to do is this:

1. make the initial request for the resource
2. the server responds with the nonce (read the first URL above if 
you're not familiar with this)
3. You create a HTTPPasswordMgr object
4. You call the add_password() method of the HTTPPasswordMgr object and 
pass in the data for building a password.
5. You pass the HTTPPasswordMgr to a HTTPDigestAuthHandler object and 
then call handle_authentication_request() and pass in the relevant 
parameters.

It's pretty confusing to me.  Hopefully someone else on the list can 
shed better light on this one.


Erik