Python HTTPS 客户端通过代理进行基本身份验证
在 Python 中,我想通过具有基本身份验证的 HTTPS 从网站检索内容。我需要磁盘上的内容。我位于 Intranet 上,信任 HTTPS 服务器。平台是 Windows 上的 Python 2.6.2。
我一直在玩 urllib2,但到目前为止还没有成功。
我有一个正在运行的解决方案,通过 os.system() 调用 wget:
wget_cmd = r'\path\to\wget.exe -q -e "https_proxy = http://fqdn.to.proxy:port" --no-check-certificate --http-user="username" --http-password="password" -O path\to\output https://fqdn.to.site/content'
我想摆脱 os.system()。这在Python中可能吗?
From Python, I would like to retrieve content from a web site via HTTPS with basic authentication. I need the content on disk. I am on an intranet, trusting the HTTPS server. Platform is Python 2.6.2 on Windows.
I have been playing around with urllib2, however did not succeed so far.
I have a solution running, calling wget via os.system():
wget_cmd = r'\path\to\wget.exe -q -e "https_proxy = http://fqdn.to.proxy:port" --no-check-certificate --http-user="username" --http-password="password" -O path\to\output https://fqdn.to.site/content'
I would like to get rid of the os.system(). Is that possible in Python?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
代理和 https 无法使用 urllib2 很长一段时间。它将在 python 2.6 (v2.6.3) 的下一个发布版本中修复。
与此同时,您可以重新实现正确的支持,这就是我们为 Mercurial 所做的: http:// /hg.intevation.org/mercurial/crew/rev/59acb9c7d90f
Proxy and https wasn't working for a long time with urllib2. It will be fixed in the next released version of python 2.6 (v2.6.3).
In the meantime you can reimplement the correct support, that's what we did for mercurial: http://hg.intevation.org/mercurial/crew/rev/59acb9c7d90f
试试这个(请注意,您还必须填写服务器的领域):
Try this (notice that you'll have to fill in the realm of your server also):
你也可以尝试这个:
http://code.google.com/p/python-httpclient/
(它还支持服务器证书的验证。)
You could try this too:
http://code.google.com/p/python-httpclient/
(It also supports the verification of the server certificate.)