Using specific SSL version TLSv1.2

I ran into a problem with a TLSv1.2 site using the Travis Ubuntu precise containers, which is documented at https://github.com/travis-ci/travis-ci/issues/4757

I was able to work around the problem using:

``` python
import ssl, urllib3
pm = urllib3.PoolManager(ssl_version=ssl.PROTOCOL_TLSv1_2)
r = pm.request('GET', 'http://proofwiki.org/wiki/Main_Page')
```

I'd like to workaround it using `requests` if possible, and it seems like it should be possible according to
http://docs.python-requests.org/en/master/user/advanced/#example-specific-ssl-version

However when I try to follow that recipe (below) on Python 2.7.9+ / 3.4+, `requests.exceptions.SSLError: ("bad handshake: SysCallError(104, 'ECONNRESET')",)` is raised.

``` python
import ssl
import sys

import requests

from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager

class Tls12HttpAdapter(HTTPAdapter):
    """Transport adapter that forces use of TLSv1.2."""

    def init_poolmanager(self, connections, maxsize, block=False):
        """Create and initialize the urllib3 PoolManager."""
        self.poolmanager = PoolManager(
            num_pools=connections, maxsize=maxsize,
            block=block, ssl_version=ssl.PROTOCOL_TLSv1_2)


url = sys.argv[1]

s = requests.Session()
s.mount(url, Tls12HttpAdapter())
r = s.get(url)
print(r.status_code)
```

https://github.com/jayvdb/my-ci-test/blob/tls12/requests_explicit.py

Full backtrace at https://travis-ci.org/jayvdb/my-ci-test/jobs/132022039


So, adopters are selected based on a prefix match against a lowercased normalised form of the URL. That means it's rarely a good idea to add an adapter that is mounted against the _whole_ URL: scheme and host is better. 

Try mounting the adapter using a more restrictive URL. 


Well it works if I mount the eventual target scheme and hostname (i.e. https://proofwiki.org) , but if fails if I mount the intermediary scheme and hostname (i.e. https://www.proofwiki.org) and as already mentioned it fails if I mount the http scheme and hostname that my program receives as input, which is http://proofwiki.org .


So we use a different adapter for each request, so if you use the http URL to mount the adapter it definitely won't work: you'll need to use the URL for the _actual_ host that requires TLSv1.2. If you want you can mount unconditionally for `https://`, assuming all your hosts support TLSv1.2


Ok, thanks, mounting unconditionally for https:// worked for my scenario.


I'm glad we found something that works for you! Thanks for letting us know!


Hello,
I tried mounting my adapter separately but I get the same error. 

```
class Myadapter(HTTPAdapter):
    def init_poolmanager(self, connections, maxsize, block=False):
        """Create and initialize the urllib3 PoolManager."""
        self.poolmanager = PoolManager(
            num_pools=connections, maxsize=maxsize,
            block=block, ssl_version=ssl.PROTOCOL_TLSv1_2)


def requests_session(session=None):
    try:
        adapter = Myadapter()
        session.mount('http://', adapter)
        session.mount('https://', adapter)
        return session
    except Exception:
        ('requests_session - Error Api calls')

data = {
    'username' : 
    'password' :
}
headers = {
    'Content-Type' : 'application/json'
}
session_id = requests.Session()
requests_r= requests_session(session=session_id)
resp= requests_r.post(url, data=data, headers=headers).json()
```
The Error that I get is:
```
Max retries exceeded with url: some_random_api (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
```




You should add `session.verify = "/path/to/ca_cert.pem"` @ankitpatnaik :

```python
session_id = requests.Session()
session_id.verify = "/path/to/ca_cert.pem"
requests_r = requests_session(session=session_id)
```

or add `verify=False` in your requests, but I don't suggest that in production:

```python
resp = requests_r.post(url, data=data, headers=headers, verify=False).json()
```