인트라넷에서 사이트를 구문 분석하려고하는데 아래에서 인증 할 때 인증이 필요하다는 오류가 나타납니다. 왜이 401 오류가 계속 발생합니까?Python이 ntlm을 사용하여 인증 할 수 없습니다.
미리 감사드립니다.
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)
최신 http://code.google.com/p/python-ntlm/ 및 http://stackoverflow.com/a/14904367/819417을 사용해보십시오. –