How does Python urllib2 https work?

妖精的绣舞 提交于 2019-12-11 08:48:48

问题


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?


回答1:


< Python 2.7.9:_

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

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

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

Update 20150120:

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

Thanks to @EnnoGröper for the notice.



来源:https://stackoverflow.com/questions/18062937/how-does-python-urllib2-https-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!