SSL verification error when using requests sessions

## The problem
When using requests sessions to connect to a https website with a self signed certificate, requests throws a SSLError. It is working pefectly fine when using requests without sessions.

## What I am using:
   * python2.7
   * requests (2.18.4)
   * exported REQUESTS_CA_BUNDLE environment variable
   * Imported certificate to ca-certificates on underlying Debian os

Note: The certificate validates more than one hostname (e.g. kubernetes, kubernetes.default, kubernets.default.svc, kubernetes.default.svc.cluster.local, ...)

## Steps to reproduce
```python
# Normal request
import requests
requests.get('https://kubernetes.default.svc')
<Response [401]>

# Session request
s = requests.Session()
request = requests.Request('GET', 'https://kubernetes.default.svc')
prepared_request = s.prepare_request(request)
response = s.send(prepared_request)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 612, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 504, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='kubernetes.default.svc', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)'),))
```

You should prepare the request using the `Session`:

```python
request = requests.Request('GET', 'https://kubernetes.default.svc')
prepared_request = s.prepare_request(request)
response = s.send(prepared_request)
```

Thanks for the quick response Lukasa, I did make a mistake copy/pasting on the issue. Sorry.
I will update the issue too. Could you please reopen?

Here is the request output using the session to prepare:
```python
import requests
# Normal request
requests.get('https://kubernetes.default.svc')
<Response [401]>

# Session request
s = requests.Session()
request = requests.Request('GET', 'https://kubernetes.default.svc')
prepared_request = s.prepare_request(request)
response = s.send(prepared_request)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 612, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 504, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='kubernetes.default.svc', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)'),))
```

Yup, you're missing some environmental settings here. This is something that is not well handled by the prepared request flow. You can try doing this:

```python
s = requests.Session()
request = requests.Request('GET', 'https://kubernetes.default.svc')
prepared_request = s.prepare_request(request)

settings = s.merge_environment_settings(prepared_request.url, None, None, None, None)
response = s.send(prepared_request, **settings)
```

Thanks Lukasa, this works like a charm! I will try to figure out what exactly is wrong with my environment.

Nothing is wrong with it: just the prepared request flow doesn't normally consider the environment. =)

That is good to know. Maybe it can be added to the documentation page:
http://docs.python-requests.org/en/master/user/advanced/#session-objects

This page documents the usage of Sessions, but it doesn't mention the environment. Also the SSL section does not mention this.

It should probably go into the prepared request section, not the session section. =) I'd welcome a patch though.

Do you mean a patch on the documentation, or to fix the prepared request to use the environment?
I am not really familiar with the code, but I can take a crack at it.

A patch on the documentation. :smile:

Max retries exceeded with url: / (Caused by SSLError(SSLError(1, u'[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)'),))

I know this issue is closed but I had the same issue and with hours of research and attempting potential solutions nothing seemed to work. **Ended up uninstalling and reinstalling Python and have not ran into this issue since, I highly suggest you try this if you are still experiencing this issue and have tried multiple potential resolutions.**