SSLError :(“握手不正确:SysCallError(54,'ECONNRESET')“,) [英] SSLError: ("bad handshake: SysCallError(54, 'ECONNRESET')",)
问题描述
我正在尝试使用请求库将发布请求发送到服务器.我正在使用以下堆栈:
I am trying to fire a post request to the server using requests library. I am using the following stack:
appdirs==1.4.3
asn1crypto==0.22.0
boto==2.46.1
certifi==2017.4.17
cffi==1.10.0
cryptography==1.8.1
enum34==1.1.6
idna==2.5
inflection==0.3.1
ipaddress==1.0.18
ndg-httpsclient==0.4.2
packaging==16.8
pyasn1==0.2.3
pycparser==2.17
pyOpenSSL==17.0.0
pyparsing==2.2.0
qds-sdk==1.9.6
requests==2.13.0
six==1.10.0
urllib3==1.21.1
但是请求始终失败,并显示以下错误:
But the requests always fails with the below error:
Traceback (most recent call last):
File "/usr/local/bin/qds.py", line 625, in <module>
sys.exit(main())
File "/usr/local/bin/qds.py", line 575, in main
return cmdmain(a0, args)
File "/usr/local/bin/qds.py", line 203, in cmdmain
return globals()[action + "action"](cmdclass, args)
File "/usr/local/bin/qds.py", line 138, in runaction
cmd = cmdclass.run(**args)
File "/usr/local/lib/python2.7/site-packages/qds_sdk/commands.py", line 96, in run
cmd = cls.create(**kwargs)
File "/usr/local/lib/python2.7/site-packages/qds_sdk/commands.py", line 77, in create
return cls(conn.post(cls.rest_entity_path, data=kwargs))
File "/usr/local/lib/python2.7/site-packages/qds_sdk/connection.py", line 59, in post
return self._api_call("POST", path, data)
File "/usr/local/lib/python2.7/site-packages/qds_sdk/connection.py", line 98, in _api_call
return self._api_call_raw(req_type, path, data=data, params=params).json()
File "/usr/local/lib/python2.7/site-packages/qds_sdk/connection.py", line 86, in _api_call_raw
r = x.post(url, timeout=300, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 535, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 488, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 609, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 497, in send
raise SSLError(e, request=request)
SSLError: ("bad handshake: SysCallError(54, 'ECONNRESET')",)
当我使用打开0.9.8连接到服务器时,出现以下错误:
When I use open 0.9.8 to connect to server, the following error is given:
> openssl s_client -connect <ip>:443
CONNECTED(00000003)
write:errno=54
但是在openssl上使用较高版本时,连接成功,我认为python正在以某种方式使用较低版本,但是当我检查ssl时,它将显示较高版本:
But with a higher version on openssl the connection succeeds, I think that python is somehow using the lower version, but when I check ssl, it show the higher version:
> python -c 'import ssl; print(ssl.OPENSSL_VERSION)'
OpenSSL 1.0.2k 26 Jan 2017
不确定这里发生了什么.我不确定如何格式化它,对此感到抱歉.
Not sure what is happening here. I am not sure how to format this, sorry for that.
推荐答案
我能够找到此问题的解决方案,我只是在创建PoolManager时将ssl协议类型从"ssl.PROTOCOL_TLSv1"更改为"ssl.PROTOCOL_TLSv1_2"随后,这解决了上述问题:
I was able to find solution for this issue, I just changed the ssl protocol type while creating PoolManager from "ssl.PROTOCOL_TLSv1" to "ssl.PROTOCOL_TLSv1_2" as follows, this solved the above issue:
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
ssl_version=ssl.PROTOCOL_TLSv1_2)
但是上面将给出InsecureRequests警告,您可以使用以下命令来取消警告:
But the above will give InsecureRequests warnings, you can suppress the same by using the following command:
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
希望有帮助.
这篇关于SSLError :(“握手不正确:SysCallError(54,'ECONNRESET')“,)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!