<HEAD></HEAD>
<BODY >
<P>Hi John,</P>
<P>thanks for answering. I digged a lot deeper now into the code... and I installed the latest mechanize code separately and tried it out. The latest mechanize version works correct, I can access the site easily with a simple script.</P>
<P>I did then something ugly ;-) - I copied the latest mechanize code over the mechanize code provided by twill to see if the bug is purely within mechanize. It still doesn't work with Twill, so I suggest that somehow the 2.4er tweaking (I use 2.4) from the side of twill is the cause.</P>
<P>I tried to figure out if the BasicAuth handler is called and came to the following code:</P>
<P>_opener.py (Lines 176 - 180): </P>
<P> # In Python >= 2.4, .open() supports processors already, so we must<BR> # call ._open() instead.<BR> urlopen = getattr(urllib2.OpenerDirector, "_open",<BR> urllib2.OpenerDirector.open)<BR> response = urlopen(self, req, data)<BR></P>
<P>Here I'm lost... no idea why you copy most of the code of urllib2 and then reuse some portions of it... But i don't have the python source of urllib2 and I can't dig deeper. </P>
<P>What I found also interesting is that twill installs a own HTTPHandler (for whatever reason, I don't know what WSGI is...). Maybe this is the cause (_browser.py)?</P>
<P>def build_http_handler():<BR> from mechanize._urllib2 import HTTPHandler</P>
<P> class MyHTTPHandler(HTTPHandler):<BR> def http_open(self, req):<BR> return self.do_open(wsgi_intercept.WSGI_HTTPConnection, req)</P>
<P> return MyHTTPHandler</P>
<P>This will have to wait until next week since I'm leaving now the corporate environment.</P>
<P>Regards,</P>
<P>Andrew</P>
<P> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>On Fri, 2 Mar 2007, subscriptions@smart-knowhow.de wrote: </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>[...] </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>> What I found seems to be curious: the password handler are coded in </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>> _auth.py within mechanize. If I put debug code in the "add_password" </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>> function of HTTPPasswordMgr then the corresponding code is executed if </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>> is issue a "add_auth" command. </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>They are forked because the urllib2 code was buggy in 2.4. I submitted </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>the fixes to SF, and they're there in Python 2.5. Also, ISTR I added a </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>new proxy password manager to make the front-end proxy auth interface </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>friendlier (probably I should have written a new one from scratch rather </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>than derivint it from the urllib2 code...). </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>> The corresponding find_user_password function is never called (at least </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>> in my case). I'm currently trying to figure out why... </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>That suggests you're not getting the expected 401 response from the </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>server. </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>Turn on logging of HTTP request and response headers -- either in twill, </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>or using a simple mechanize script like the one I posted. To turn on the </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>logging you need in mechanize: </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>import mechanize </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>hh = mechanize.HTTPHandler() </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>hsh = mechanize.HTTPHandler() </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>hh.set_http_debuglevel(1) </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>hsh.set_http_debuglevel(1) </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>opener = mechanize.build_opener(hh, hsh) </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>response = opener.open(url) </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">># etc. </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>John </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">> </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>_______________________________________________ </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>twill mailing list </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>twill@lists.idyll.org </P>
<P style="MARGIN-TOP: 2px; MARGIN-BOTTOM: 2px">>http://lists.idyll.org/listinfo/twill</P></BODY>