【发布时间】:2017-04-23 09:02:55
【问题描述】:
谁能解释我通过python登录这个链接(ftpservice.acesphere.com)
【问题讨论】:
-
在您的请求中带上 cookie/authen 令牌;否则,您的请求将是匿名的。
标签: python-2.7 python-requests urllib2 urllib urlopen
谁能解释我通过python登录这个链接(ftpservice.acesphere.com)
【问题讨论】:
标签: python-2.7 python-requests urllib2 urllib urlopen
您尝试访问的 URL 需要 NTLM 身份验证。你可以试试python-ntlm包:
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()
【讨论】:
你得到这个异常:
urllib2.HTTPError: HTTP Error 401: Unauthorized
这意味着该网站正在返回 HTTP 401 Unauthorized 状态代码。捕获异常或修改您的请求以不产生此错误。
【讨论】: