durusmail: quixote-users: authentication via urllib2
authentication via urllib2
2005-02-28
authentication via urllib2
Mario Ruggier
2005-02-28
On the qx wiki, there's this, that descibes the receiving end of basic
auth:
http://quixote.ca/qx/HttpBasicAuthentication

It would be nice if this page could be a little less dry...

mario


On Feb 28, 2005, at 12:39 PM, Michele Simionato wrote:

> 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