[twill] add_auth
John J Lee
jjl at pobox.com
Tue Sep 19 11:51:16 PDT 2006
On Tue, 19 Sep 2006, Titus Brown wrote:
[...]
> Here's the code from twill:
>
> creds = urllib2.HTTPPasswordMgr()
> creds.add_password(realm, uri, user, passwd)
> mechanize_browser.set_password_manager(creds)
>
> Should that work?
>
No!
1. Never use urllib2:
(search for the word 'IMPORTANT' ;-)
http://wwwsearch.sourceforge.net/mechanize/
or, since SF seems a bit dodgy today:
http://codespeak.net/svn/wwwsearch/mechanize/trunk/README.html.in
To be explicit, here's the relevant bit:
The classes and functions exported by mechanize in its public interface
that come straight from urllib2 (e.g. FTPHandler, at the time of writing)
do work with mechanize (duh ;-). Exactly which of these classes and
functions come straight from urllib2 without extension or modification
will change over time, though, so don't rely on it; instead, just import
everything you need from mechanize, never from urllib2, which is
explicitly OK (though not well tested ATM), subject to the other
restrictions in the list above.
(um, what the above paragraph means is: always use mechanize.Blah, not
urllib2.Blah :-)
2. Use browser.add_password() and .add_proxy_password(), not
.set_password_manager(). You don't need to make an HTTPPasswordManager
yourself any more.
If you do that, you'll get the fixes I made in 2.5 and backported to
mechanize.
John
More information about the twill
mailing list