views:

246

answers:

0

I would like to use python-ntlm with mechanize.Browser() I have got HTTPNtlmAuthHandler working with urllib2 and mechanize.urlopen() and tried to use it with Browser() but it doesn't work

Here is the code I'm using for 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)

Traceback as requested

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