Mecanización de Python con NTLM obteniendo AttributeError: la instancia de HTTPResponse no tiene ningún atributo '__iter__'
Estoy tratando de acceder a un sitio que está protegido con autenticación NTLM usando python-ntlm y mecanize pero estoy recibiendo este error.
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__'
Soy capaz de obtener una respuesta adecuada cuando uso la biblioteca urllib2. Pero por alguna razón, falla cuando intento acceder a ella utilizando mecanizar.
Este es el código que tengo.
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())
¿Alguien tiene alguna idea de lo que está pasando? ¿Estoy haciendo algo mal aquí?