durusmail: quixote-users: authentication via urllib2
authentication via urllib2
2005-02-28
authentication via urllib2
Michele Simionato
2005-02-28
Suppose I want to access a Quixote page via urllib2 using basic HTTP
authentication with something like this:

import urllib2
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('quixote', 'localhost:8080', 'myusername',
'mypassword')
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
urllib2.urlopen('http://localhost:8080/mypage')

Internally, mypage will be a method of a Directory class; how do
I access the username and password from within the method?
I am looking for a get_request().get_user_passwd() or something
like that. Or should I access the HTTP headers?
TIA,

               Michele Simionato

reply