【发布时间】:2010-11-05 00:46:24
【问题描述】:
Python 2.6.1 中的urllib2 是否支持通过 https 进行代理?
我在http://www.voidspace.org.uk/python/articles/urllib2.shtml找到了以下内容:
注意
目前 urllib2 不支持 通过 a 获取 https 位置 代理。这可能是个问题。
我正在尝试自动登录网站并下载文档,我有有效的用户名/密码。
proxy_info = {
'host':"axxx", # commented out the real data
'port':"1234" # commented out the real data
}
proxy_handler = urllib2.ProxyHandler(
{"http" : "http://%(host)s:%(port)s" % proxy_info})
opener = urllib2.build_opener(proxy_handler,
urllib2.HTTPHandler(debuglevel=1),urllib2.HTTPCookieProcessor())
urllib2.install_opener(opener)
fullurl = 'https://correct.url.to.login.page.com/user=a&pswd=b' # example
req1 = urllib2.Request(url=fullurl, headers=headers)
response = urllib2.urlopen(req1)
我已经让它适用于类似的页面,但没有使用 HTTPS,我怀疑它没有通过代理 - 它只是以与我没有指定代理时相同的方式卡住。我需要通过代理出去。
我需要进行身份验证但不使用基本身份验证,通过 https 站点时 urllib2 是否会进行身份验证(我通过 url 向站点提供用户名/密码)?
编辑: 不,我用
测试过 proxies = {
"http" : "http://%(host)s:%(port)s" % proxy_info,
"https" : "https://%(host)s:%(port)s" % proxy_info
}
proxy_handler = urllib2.ProxyHandler(proxies)
我得到错误:
urllib2.URLError: urlopen 错误 [Errno 8] _ssl.c:480: EOF 发生在 违反协议
【问题讨论】:
标签: python proxy https urllib2