mechanize.Browser() でpython-ntlmを使用したいurllib2 と mechanize.urlopen() で動作する HTTPNtlmAuthHandler を取得し、Browser() で使用しようとしましたが、動作しません
これがurlopenに使用しているコードです
passman = mechanize.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)
opener = mechanize.build_opener(auth_NTLM)
mechanize.install_opener(opener)
mechanize.urlopen(baseurl)
要求に応じてトレースバック
harrisony@lithium:~$ python sitefoo.py
now running mechanize.urlopen
<addinfourl at 169181868 whose fp = <httplib.HTTPResponse instance at 0xa15858c>>
now running mechanize.Browser then br.open
Traceback (most recent call last):
File "sitescreaper.py", line 21, in <module>
br.open(baseurl)
File "/usr/lib/python2.6/dist-packages/mechanize/_mechanize.py", line 209, in open
return self._mech_open(url, data, timeout=timeout)
File "/usr/lib/python2.6/dist-packages/mechanize/_mechanize.py", line 261, in _mech_open
raise response
mechanize._response.httperror_seek_wrapper: HTTP Error 401: Unauthorized