Python urllib2 https如何工作? [英] How does Python urllib2 https work?

查看:93
本文介绍了Python urllib2 https如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看urlib2的文档,它说它支持HTTPS连接.但是,尚不清楚的是如何启用它,例如使用HTTPBasicAuth并将HTTP替换为HTTPS,还是在实际打开连接时只需要在URL中传递HTTPS?

Looking at the documentation for urlib2 it says it supports HTTPS connections. However what it doesn't make clear is how you enable it do you for example take HTTPBasicAuth and replace the HTTP with HTTPS or do you just need to pass an HTTPS in url when you actually open the connection?

推荐答案

< Python 2.7.9:_

打开连接时,您只需传递一个HTTPS URL.请注意Urllib2文档中的警告,其中指出:

You can simply pass an HTTPS URL when you open the connection. Heed the warning in the Urllib2 documentation that states:

警告HTTPS请求不会对服务器证书进行任何验证."

"Warning HTTPS requests do not do any verification of the server’s certificate."

因此,我建议使用 Python请求库,该库提供了更好的界面和许多功能,包括SSL证书验证和Unicode支持.

As such, I recommend using Python Requests library that provides a better interface and many features, including SSL Cert verification and Unicode support.

更新20150120:

Python 2.7.9添加了HTTPS主机名验证作为标准.请在 https://docs.python.org/2/library中查看更改注释/httplib.html#httplib.HTTPSConnection

Python 2.7.9 Added HTTPS Hostname verification as standard. See change comment in https://docs.python.org/2/library/httplib.html#httplib.HTTPSConnection

感谢@EnnoGröper发出通知.

Thanks to @EnnoGröper for the notice.

这篇关于Python urllib2 https如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆