【发布时间】:2016-04-08 07:20:20
【问题描述】:
我正在尝试这个简单的 python 2.7 代码:
import requests
response = requests.get(url="https://sslbl.abuse.ch", verify=False)
print response
我使用verify=False 来忽略验证 SSL 证书。
我收到以下异常:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='sslbl.abuse.ch', port=443): Max retries exceeded with url: / (Caused by <class 'socket.error'>: [Errno 10054] An existing connection was forcibly closed by the remote host
如果我尝试另一个 https 网址(如 twitter.com),一切正常。 可能是什么问题?如何像浏览器一样获得响应?
更新:
升级请求版本后,我得到相同的ConnectionError,但添加了一些警告:
C:\Python27\lib\site-packages\requests\packages\urllib3\util\ssl_.py:315: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
C:\Python27\lib\site-packages\requests\packages\urllib3\util\ssl_.py:120: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
【问题讨论】:
-
什么版本的请求?
-
为什么不在 Python3x 中使用 urllib.request 呢?请在下面查看我建议的答案。谢谢。
标签: python ssl https python-requests