Mecanismo do Python com o NTLM obtendo AttributeError: a instância HTTPResponse não possui nenhum atributo '__iter__'
Eu estou tentando acessar um site que é protegido com autenticação NTLM usando python-ntlm e mecanizar, mas estou recebendo esse erro.
File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 203, in open
File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 249, in _mech_open
File "build/bdist.macosx-10.6-universal/egg/mechanize/_mechanize.py", line 304, in _set_response
File "build/bdist.macosx-10.6-universal/egg/mechanize/_response.py", line 521, in upgrade_response
File "build/bdist.macosx-10.6-universal/egg/mechanize/_response.py", line 338, in __init__
File "build/bdist.macosx-10.6-universal/egg/mechanize/_response.py", line 353, in _set_fp
AttributeError: HTTPResponse instance has no attribute '__iter__'
Eu sou capaz de obter uma resposta adequada quando eu uso a biblioteca urllib2. Mas, por algum motivo, falha quando tento acessá-lo usando o mechanize.
Este é o código que tenho.
import urllib2
from ntlm import HTTPNtlmAuthHandler
user = '<myusername>'
password = "<mypass>"
url = "https://somesite.com"
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)
# create the NTLM authentication handler
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)
import mechanize
browser = mechanize.Browser()
handlersToKeep = []
for handler in browser.handlers:
if not isinstance(handler,
(mechanize._http.HTTPRobotRulesProcessor)):
handlersToKeep.append(handler)
browser.handlers = handlersToKeep
browser.add_handler(auth_NTLM)
response = browser.open(url)
print(response.read())
Alguém tem alguma ideia do que está acontecendo? Estou fazendo algo errado aqui?