我正在尝试这个简单的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.
答案 0 :(得分:0)
我没有将Python 2.7用于我的任务,但是我试图打开你用python3.2提供的URL(它应该适用于所有Python3x,我假设)。没有例外。这就是我所做的(&gt;&gt;&gt;省略):
from urllib.request import urlopen
url = "https://sslbl.abuse.ch"
response = urlopen(url)
type(response)
<class 'http.client.HTTPResponse'>
从Python文档中,请参阅此输出:
i = 0
with open(url) as response:
for line in response:
line = line.decode('utf-8')
if "Show more information about this SSL certificate" in line:
i += 1
print(i)
1060
我建议使用Python3x。希望这有帮助!