Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

requests.packages.urllib3.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:646) #2906

Closed
caizixian opened this issue Nov 28, 2015 · 7 comments

Comments

@caizixian
Copy link

Mac OS X 10.11.1
Python 3.5.0 from https://www.python.org/downloads/
requests (2.8.1)

>>> import ssl
>>> ssl.OPENSSL_VERSION
'OpenSSL 0.9.8zg 14 July 2015'

URL https://api.telegram.org/

@Lukasa
Copy link
Member

Lukasa commented Nov 28, 2015

That version of OpenSSL is absolutely ancient. I suspect it's the cause of your problem.

I have OS X 10.11.2 Beta, Python 3.5.0 linked against a newer version of OpenSSL (1.0.2d), and the same version of requests, and I can reach that URL fine. I highly encourage you to use a newer version of OpenSSL.

You can get this by running pip install -U requests[security].

@Lukasa Lukasa closed this as completed Nov 28, 2015
@caizixian
Copy link
Author

@Lukasa So maybe I need to install a newer version of OpenSSL using homebrew and use it to replace the old OpenSSL shipped with OS.

@Lukasa
Copy link
Member

Lukasa commented Nov 28, 2015

@caizixian It's an option, but if you pip install -U requests[security] that will grab PyOpenSSL, which includes its own copy of OpenSSL on OS X.

@caizixian
Copy link
Author

@Lukasa I had following errors when installing requests[security], both related to cffi.

  1. c/_cffi_backend.c:14:10: fatal error: 'ffi.h' file not found

    so I brew install pkg-config libffi, which solved this problem.

  2. After that, I tried to install requests[security] again, and I got Failed building wheel for cffi .

    Despite this error, pip said that all things were installed. So I checked ssl.OPENSSL_VERSION again, still the same.

FYI, my Xcode is 7.1.1

@Lukasa
Copy link
Member

Lukasa commented Nov 29, 2015

Failed building wheel for cffi is fine, you don't mind. You shouldn't check ssl.OPENSSL_VERSION because that's the standard library and doesn't get changed by the packages you just installed. Instead, you should try running python -c "from cryptography.hazmat.backends.openssl.backend import backend;print(backend.openssl_version_text())". That should print the newer OpenSSL version, and that's the one that will be used by requests.

@caizixian
Copy link
Author

pip install cryptography
pip install pyopenssl
pip install requests[security]

Problem solved.

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  5 2015, 21:12:44) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cryptography.hazmat.backends.openssl.backend import backend
>>> print(backend.openssl_version_text())
OpenSSL 1.0.2e 3 Dec 2015

@ghost
Copy link

ghost commented Feb 23, 2017

caizixian, you saved my life!!!!!
Thank you so much

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants