Visa Developer Community

Highlighted
Regular Visitor

Bad Handshake on Pythoon Client.

I have been able to access the API in Postman. However, I am still not able to access it Python. I wrote a Python client to access the API following the instructions on
https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl#sample_code_for_twoway_mutual_ss...

 

response = requests.post(url, verify = (CA_Cert), cert = (client_cert, privateKey), headers = headers, auth = (user_id, password), data = body). In my code, I have added the 3 pem files. But upon running, I still get a bad handshake error. 

I can make the calls in Postman, however.

 

Please find attachments: 

Error: 

bad_handshake.jpg

Postman Success: 
postman_success.jpg

I am referring to the tutorial here: https://developer.visa.com/pages/working-with-visa-apis/two-way-ssl
sample.jpg

2 REPLIES 2
Highlighted
Visa Dev Moderator
Visa Dev Moderator

Re: Bad Handshake on Pythoon Client.

Hi @animeshpaul91,

Happy to hear that you got Postman to work. I'll see if I can get sample Python code to share. I am not familiar with Python unfortunately. 


Best,
Stacey

Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.
Highlighted
Regular Visitor

Re: Bad Handshake on Pythoon Client.

The API calls now work on Postman. However, interestingly Python returns an SSL error leading to bad handshake. Please find below a series of cascading errors. 

 

[Running] python -u "c:\Projects\Step_Up_Bootcamp\Travelex\sbxclient.py"

Traceback (most recent call last):

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 485, in wrap_socket

    cnx.do_handshake()

  File "C:\Users\animepau\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake

    self._raise_ssl_error(self._ssl, result)

  File "C:\Users\animepau\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1663, in _raise_ssl_error

    raise SysCallError(errno, errorcode.get(errno))

OpenSSL.SSL.SysCallError: (10054, 'WSAECONNRESET')

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 672, in urlopen

    chunked=chunked,

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 376, in _make_request

    self._validate_conn(conn)

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 994, in _validate_conn

    conn.connect()

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\connection.py", line 360, in connect

    ssl_context=context,

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\util\ssl_.py", line 370, in ssl_wrap_socket

    return context.wrap_socket(sock, server_hostname=server_hostname)

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 491, in wrap_socket

    raise ssl.SSLError("bad handshake: %r" % e)

ssl.SSLError: ("bad handshake: SysCallError(10054, 'WSAECONNRESET')",)

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "C:\Users\animepau\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send

    timeout=timeout

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 720, in urlopen

    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]

  File "C:\Users\animepau\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 436, in increment

    raise MaxRetryError(_pool, url, error or ResponseError(cause))

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='sandbox.api.visa.com', port=443): Max retries exceeded with url: /bia/service/v1/scorerange (Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')")))

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "c:\Projects\Step_Up_Bootcamp\Travelex\sbxclient.py", line 42, in <module>

    response = requests.post(url, verify = (CA_Cert), cert = (client_cert, privateKey), headers = headers, auth = (user_id, password), data = body)

  File "C:\Users\animepau\Anaconda3\lib\site-packages\requests\api.py", line 116, in post

    return request('post', url, data=data, json=json, **kwargs)

  File "C:\Users\animepau\Anaconda3\lib\site-packages\requests\api.py", line 60, in request

    return session.request(method=method, url=url, **kwargs)

  File "C:\Users\animepau\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request

    resp = self.send(prep, **send_kwargs)

  File "C:\Users\animepau\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send

    r = adapter.send(request, **kwargs)

  File "C:\Users\animepau\Anaconda3\lib\site-packages\requests\adapters.py", line 514, in send

    raise SSLError(e, request=request)

requests.exceptions.SSLError: HTTPSConnectionPool(host='sandbox.api.visa.com', port=443): Max retries exceeded with url: /bia/service/v1/scorerange (Caused by SSLError(SSLError("bad handshake: SysCallError(10054, 'WSAECONNRESET')")))

 

[Done] exited with code=1 in 1.539 seconds