abhijitjaiswal
abhijitjaiswal

Reputation: 139

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')",)

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

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.

Upvotes: 1

Views: 8546

Answers (1)

abhijitjaiswal
abhijitjaiswal

Reputation: 139

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)

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)

Hope it helps.

Upvotes: 5

Related Questions