我一直在尝试解析网站,但在使用 urllib2.urlopen 时出现错误
i have been trying to parse a website and when using urllib2.urlopen i have been getting a error
谁能解释一下如何通过 python
登录此 link(ftpservice.acesphere.com)
您收到此异常:
urllib2.HTTPError: HTTP Error 401: Unauthorized
这意味着该网站正在返回 HTTP 401 未授权状态代码。捕获异常或修改您的请求以不产生此错误。
您尝试访问的 URL 需要 NTLM 身份验证。你可以试试 python-ntlm package:
from ntlm import HTTPNtlmAuthHandler
import urllib2
url = "http://ftpservice.acesphere.com/stocks/indices/master/indicesmaster_new.ace"
user = r'domain\user'
password = "password"
pm = urllib2.HTTPPasswordMgrWithDefaultRealm()
pm.add_password(None, "http://ftpservice.acesphere.com/", user, password)
auth = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(pm)
opener = urllib2.build_opener(auth)
urllib2.install_opener(opener)
response = urllib2.urlopen(url)
print response.read()
谁能解释一下如何通过 python
登录此 link(ftpservice.acesphere.com)您收到此异常:
urllib2.HTTPError: HTTP Error 401: Unauthorized
这意味着该网站正在返回 HTTP 401 未授权状态代码。捕获异常或修改您的请求以不产生此错误。
您尝试访问的 URL 需要 NTLM 身份验证。你可以试试 python-ntlm package:
from ntlm import HTTPNtlmAuthHandler
import urllib2
url = "http://ftpservice.acesphere.com/stocks/indices/master/indicesmaster_new.ace"
user = r'domain\user'
password = "password"
pm = urllib2.HTTPPasswordMgrWithDefaultRealm()
pm.add_password(None, "http://ftpservice.acesphere.com/", user, password)
auth = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(pm)
opener = urllib2.build_opener(auth)
urllib2.install_opener(opener)
response = urllib2.urlopen(url)
print response.read()