I am trying to parse a site on my intranet and when authenticating as below I get an error saying that authentication is required, which I have already done. Why am I still getting this 401 error?
Thanks in advance!
File "C:\Python27\lib\urllib2.py", line 531, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 401: Authorization Required
import urllib2
from ntlm import HTTPNtlmAuthHandler
user = r'domain\myuser'
password = 'mypasswd'
url = 'http://myinternal.homepage'
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)
# create the NTLM authentication handler
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)
# create and install the opener
opener = urllib2.build_opener(auth_NTLM)
urllib2.install_opener(opener)
# retrieve the result
response = urllib2.urlopen(url)
print(response)