TLS Handshake issue | Python 2.7.6 | Requests 2.13.0

Hi All

I'm kinda new to python and I'm facing issues with TLS handshakes. My project currently uses python 2.7.6, requests 2.13.0 with no pip. I'm running on a Windows machine. I've been currently asked to stick with these versions.

I'm using code similar to the the one below.
```
import requests
import requests.packages.urllib3

requests.packages.urllib3.disable_warnings()
response = requests.get('https://www.verisign.com')
print(response.status_code)
```

After running this code, I get the following error
`requests.exceptions.SSLError: [Errno 8] _ssl.c:507: EOF occurred in violation of protocol`


I also tried this piece of code to check the underlying ssl library

```
import socket, ssl, certifi

print(certifi.where())

CIPHERS = (
    'AES256-SHA:ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+HIGH:'
    'DH+HIGH:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+HIGH:RSA+3DES:!aNULL:'
    '!eNULL:!MD5'
)

server_address = ('www.verisign.com', 443)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssl_sock = ssl.wrap_socket(s, 
                            cert_reqs=ssl.CERT_REQUIRED, 
                            ca_certs=certifi.where(),
                            ssl_version=ssl.PROTOCOL_TLSv1,
                            ciphers=CIPHERS)
ssl_sock.connect(server_address)

print(ssl_sock.cipher())
```
This fails with

```
File "***python\2.7.6\lib\ssl.py", line 305, in do_handshake
    self._sslobj.do_handshake()
socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host
```


I suspect this might have something to do with the older versions of TLS supported by python 2.7.6. Can anyone help me with this issue and how to fix this?

There is no excuse to still be using python 2. Its being depricated in 2020 so dont expect anyone to help you, or things to ever be update for py2 after that date. Try running the same code in python 3 and the newest version of requests. 

I agree, and I'm pushing to use a higher version of python. I've also pointed out to them regarding the deprecation as well. They are still under consideration.

I've run the code with 2.7.14 and the code works well.

The other observation is this issue seems to work fine with certain websites and doesn't seem to work on others. How would I be able to troubleshoot these issues ?

I don't know, The only thing that *could* be done would be to upgrade since it seems this was a fixed bug if it works on a newer version of python 2. That's really your only option.

I found a possible explanation here [Cannot download from an HTTPS site (ssl) with wget?](https://unix.stackexchange.com/a/479830/101949)

Basically, the openssl version on python 2.7.6 is 0.9.8 which only supports TLS 1.0. Support for TSL 1.1 and 1.2 comes with openssl version 1.0.1 (https://cpython-test-docs.readthedocs.io/en/latest/library/ssl.html#module-ssl)

If a website offers only only TLS 1.2 support during the SSL negotiation, then we'd get the above errors.

Would it be possible to bootstrap support for TLS 1.2 ?

Are you able to at least upgrade to a recent Python 2.7?

* 2.7.6 was released on 2013-11-10, six years ago.

* 2.7.17 is the newest, released on 2019-10-19.

https://www.python.org/dev/peps/pep-0373/

I doubt anyone is going to support a six-year-old Python 2.7 version, especially as the 2.7 EOL date is about 6 weeks away.


If wishes were upgrades... Unfortunately, upgrade is not a decision I alone can take.

I found a work-around instead...