requests: requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:645)
Here is the first issue. https://github.com/kennethreitz/requests/issues/2906
Python 3.5.1 (https://www.python.org/downloads/) Virtualenv 14.0.5 Mac OS X 10.11.3
First, I created a virtualenv and pip install requests[security]
Then I got
>>> from cryptography.hazmat.backends.openssl.backend import backend
>>> print(backend.openssl_version_text())
OpenSSL 1.0.2f 28 Jan 2016
which was what I expected.
Everything worked great for about an hour.
Then, some of my own scripts crashed which was normal. After that, when I try to run my script again, I got following exceptions
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:645)
requests.packages.urllib3.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:645)
requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:645)
So I opened another Python console and
>>> requests.get("https://www.google.com")
<Response [200]>
>>> requests.get("https://www.telegram.org")
Traceback (most recent call last):
File "VirtualenvPath/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
body=body, headers=headers)
File "VirtualenvPath/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 345, in _make_request
self._validate_conn(conn)
File "VirtualenvPath/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 784, in _validate_conn
conn.connect()
File "VirtualenvPath/lib/python3.5/site-packages/requests/packages/urllib3/connection.py", line 252, in connect
ssl_version=resolved_ssl_version)
File "VirtualenvPath/lib/python3.5/site-packages/requests/packages/urllib3/util/ssl_.py", line 305, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 376, in wrap_socket
_context=self)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 747, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 983, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/ssl.py", line 628, in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:645)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "VirtualenvPath/lib/python3.5/site-packages/requests/adapters.py", line 376, in send
timeout=timeout
File "VirtualenvPath/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 588, in urlopen
raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:645)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "VirtualenvPath/lib/python3.5/site-packages/requests/api.py", line 67, in get
return request('get', url, params=params, **kwargs)
File "VirtualenvPath/lib/python3.5/site-packages/requests/api.py", line 53, in request
return session.request(method=method, url=url, **kwargs)
File "VirtualenvPath/lib/python3.5/site-packages/requests/sessions.py", line 468, in request
resp = self.send(prep, **send_kwargs)
File "VirtualenvPath/lib/python3.5/site-packages/requests/sessions.py", line 576, in send
r = adapter.send(request, **kwargs)
File "VirtualenvPath/lib/python3.5/site-packages/requests/adapters.py", line 447, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:645)
>>>
So I rebooted, uninstalled all these libs and pip install them again. Everything worked again.
But after 1 hour or so, same exception again.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 77 (33 by maintainers)
Commits related to this issue
- Adding credit https://github.com/kennethreitz/requests/issues/3006 directly helped with one particular fix. Adding credit. — committed to danclegg/python-CAS-RESTful-client by danclegg 8 years ago
- Try installing pyopenssl https://github.com/requests/requests/issues/3006 — committed to rtlee9/comparatory-api by rtlee9 7 years ago
pip install --force-reinstall requests[security]solved it for me.@the-efi Do you have
pyopenssl,pyasn1, andndg-httpsclientinstalled?Ok, so the easiest way for you to fix this up is to run
python3 -m pip install pyopenssl pyasn1 ndg-httpsclient. That should fix your problem, but if it doesn’t we can pursue more aggressive options.You’re another person who is winning our competition of who can attempt to contact the worst HTTPS server in the world. This server is awfully configured, it is entirely insecure. The reason you’re encountering this problem is because Requests no longer supports any of the cipher suites this server supports because they’re all either weak or insecure. In the first instance I recommend you attempt to pressure someone to fix the server, but if you really must contact it you can re-add 3DES like this.
Any update on this one? It happens quite a lot when working with aws.
Hi guys! Got this errors too. Using python3 and installing the combo (pyopenssl ndg-httpsclient pyasn1 urllib3) did the trick. But i go curious how python2.7 behaved on OS X and Ubuntu:
Scenario 001
Error
Scenario 002
Error
Scenario 004
Error is gone
Scenario 003
Error is gone
This almost certainly means the ciphers being offered to the remote peer are not acceptable. If you use
openssl s_client -connect <host>:<port>to the website you’re trying to contact, can you tell me what the output is? (Please make sure to do so with the OpenSSL 1.0.2g you’re using).Having the same exception on Python 2.7.11/OSX when pounding a server with
requestsundergevent. Could this be related?@Lukasa I think since requests is shipped with its own urllib3, I could not import urllib3 alone. And the following result confirms it.
Just as an FYI, this error also occurs when SSL isn’t enabled on the server you’re connecting to.
I was having this issue on Mac OSX Sierra v 10.12.0. Tried everything on this thread, didn’t work. Finally upgraded my OS to v10.12.6 and the issue went away.
I came across the same bug AFTER switching to aws and putting the app behind an elastic loadbalancer, never occured before.
I have urllib3 installed as well.
Is there hope for installing pyopenssl? I tried and there were lot’s of c-level errors (which may be cause of some missing parts in my docker image).