[twill] Question about HTTP basic authentication handling

John J Lee jjl at pobox.com
Fri Mar 2 05:57:52 PST 2007

On Fri, 2 Mar 2007, subscriptions at smart-knowhow.de wrote:
> I'm currently not able to log in with twill into a site, while I can 
> access the site via urllib2 with the following script:
> import urllib2
> passmgr = urllib2.HTTPBasicAuthHandler()
> passmgr.add_password("LDAP Intranet-Login:", 'webportal', 'myname', 'mypw')
> If I use the same credentials within a "add_auth" command in twill it 
> won't work (I get a 403 access forbidden).
> What I was wondering about is: twill uses HTTPPasswordMgr where my 
> script uses HTTPBasicAuthHandler, and my script installs the handler.
> I'm not deep into the inner workings of urllib2 and mechanize - any 
> pointer would be helpful.

mechanize._auth.HTTPBasicAuthHandler has an 
mechanize._auth.HTTPPasswordManager (or a subtype).  Those classes are 
forked copies of the urllib2 classes of the same names.

I don't know the twill code.  If Titus doesn't pop up with the solution, 
you can try to locate the problem by writing the corresponding mechanize 
code.  Something like (UNTESTED):

br = mechanize.Browser()
# using 3 argument form here -- optional 4th arg is realm ("LDAP Intranet-Login:")
br.add_password('webportal', 'myname', 'mypw')
print br.read()


More information about the twill mailing list