Hi John,
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.
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.
I tried to figure out if the BasicAuth handler is called and came to the following code:
_opener.py (Lines 176 - 180):
# In Python >= 2.4, .open() supports processors already, so we must
# call ._open() instead.
urlopen = getattr(urllib2.OpenerDirector, "_open",
urllib2.OpenerDirector.open)
response = urlopen(self, req, data)
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.
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)?
def build_http_handler():
from mechanize._urllib2 import HTTPHandler
class MyHTTPHandler(HTTPHandler):
def http_open(self, req):
return self.do_open(wsgi_intercept.WSGI_HTTPConnection, req)
return MyHTTPHandler
This will have to wait until next week since I'm leaving now the corporate environment.
Regards,
Andrew
>On Fri, 2 Mar 2007, subscriptions-sES7kRODLsuUo3SRjZBpwA@public.gmane.org wrote:
>[...]
>> What I found seems to be curious: the password handler are coded in
>> _auth.py within mechanize. If I put debug code in the "add_password"
>> function of HTTPPasswordMgr then the corresponding code is executed if
>> is issue a "add_auth" command.
>
>They are forked because the urllib2 code was buggy in 2.4. I submitted
>the fixes to SF, and they're there in Python 2.5. Also, ISTR I added a
>new proxy password manager to make the front-end proxy auth interface
>friendlier (probably I should have written a new one from scratch rather
>than derivint it from the urllib2 code...).
>
>
>> The corresponding find_user_password function is never called (at least
>> in my case). I'm currently trying to figure out why...
>
>That suggests you're not getting the expected 401 response from the
>server.
>
>Turn on logging of HTTP request and response headers -- either in twill,
>or using a simple mechanize script like the one I posted. To turn on the
>logging you need in mechanize:
>
>import mechanize
>hh = mechanize.HTTPHandler()
>hsh = mechanize.HTTPHandler()
>hh.set_http_debuglevel(1)
>hsh.set_http_debuglevel(1)
>opener = mechanize.build_opener(hh, hsh)
>
>response = opener.open(url)
># etc.
>
>
>John
>
>_______________________________________________
>twill mailing list
>twill-zFNWeKVCUJJD5a/XDn3G2A@public.gmane.org
>http://lists.idyll.org/listinfo/twill