Sslv3 alert handshake failure with pyopenssl

I’m receiving a bad handshake error when attempting to make a post with requests. 

Here is my code:

```
import requests

url = "https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests"

r = requests.post(url=url, cert=("/path/to/client_cert.pem", "/path/to/private_key.pem"), verify= "/path/to/server_cert.pem")
```

I get the following exception:

```
 File "/home/www-data/py2713env/lib/python2.7/site-packages/requests/api.py", line 112, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/www-data/py2713env/lib/python2.7/site-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/www-data/py2713env/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/www-data/py2713env/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/home/www-data/py2713env/lib/python2.7/site-packages/requests/adapters.py", line 506, in send
    raise SSLError(e, request=request)
SSLError: HTTPSConnectionPool(host='mss.swicpc.bankgirot.se', port=443): Max retries exceeded with url: /swish-cpcapi/api/v1/paymentrequests (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_read_bytes', 'sslv3 alert handshake failure')],)",),))

```
The error disappears if I remove pyopenssl from urllib3, by including this line of code before making the request: 

```
from requests.packages.urllib3.contrib import pyopenssl
pyopenssl.extract_from_urllib3()
```
So I'm guessing that there is a problem with the current pyopenssl version I'm using. 

System Information:

    $ python -m requests.help

```
{
  "chardet": {
    "version": "3.0.4"
  }, 
  "cryptography": {
    "version": "2.1.3"
  }, 
  "idna": {
    "version": "2.6"
  }, 
  "implementation": {
    "name": "CPython", 
    "version": "2.7.13"
  }, 
  "platform": {
    "release": "3.13.0-042stab123.3", 
    "system": "Linux"
  }, 
  "pyOpenSSL": {
    "openssl_version": "1010007f", 
    "version": "17.4.0"
  }, 
  "requests": {
    "version": "2.18.4"
  }, 
  "system_ssl": {
    "version": "1000106f"
  }, 
  "urllib3": {
    "version": "1.22"
  }, 
  "using_pyopenssl": true
}
```
Any suggestions on how to fix this problem with pyopenssl?

Your pyopenssl is using a much newer version of OpenSSL. This likely includes some extra fields in the TLS handshake that the server doesn't like very much. My recommendation is to remove pyopenssl from your environment.

Thank you Lukasa! So, this error occurs because I’m using a TLS protocol which the server i’m trying to connect to does not support? Just want to make sure I understand you correctly (sorry I’m a noob).

Do you think this problem can be circumvented using a HTTPAdapter to provide a custom SSLContext (with a different TLS protocol) to urllib3?

I would like to keep pyopenssl in my environment because later on I need to use an encrypted client certificate. I know support for this can be added using requests HTTPAdapter (acc. to issue #1573). However this also requires pyopenssl according to my understanding.

I doubt the problem is a protocol, more likely a cipher suite or extension. You do not need PyOpenSSL to handle an encrypted client certificate.