OpenSSL.SSL.SysCallError: (-1, 'Unexpected EOF')
See original GitHub issueI run following code to retrieve a page on www.cnyes.com
import requests
url = 'https://www.cnyes.com/global/IndexImmediateQuotedPrice/'
r = requests.get(url)
Following errors occur
Actual Result
C:\ProgramData\Anaconda3\envs\p36\python.exe D:/projects/DailyReport/scripts/test/test_requests.py Traceback (most recent call last): File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\contrib\pyopenssl.py”, line 441, in wrap_socket cnx.do_handshake() File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\OpenSSL\SSL.py”, line 1806, in do_handshake self._raise_ssl_error(self._ssl, result) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\OpenSSL\SSL.py”, line 1539, in _raise_ssl_error raise SysCallError(-1, “Unexpected EOF”) OpenSSL.SSL.SysCallError: (-1, ‘Unexpected EOF’)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\connectionpool.py”, line 601, in urlopen chunked=chunked) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\connectionpool.py”, line 346, in _make_request self._validate_conn(conn) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\connectionpool.py”, line 850, in validate_conn conn.connect() File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\connection.py”, line 326, in connect ssl_context=context) File "C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\util\ssl.py", line 329, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\contrib\pyopenssl.py”, line 448, in wrap_socket raise ssl.SSLError(‘bad handshake: %r’ % e) ssl.SSLError: (“bad handshake: SysCallError(-1, ‘Unexpected EOF’)”,)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\requests\adapters.py”, line 440, in send timeout=timeout File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\connectionpool.py”, line 639, in urlopen _stacktrace=sys.exc_info()[2]) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\urllib3\util\retry.py”, line 388, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=‘www.cnyes.com’, port=443): Max retries exceeded with url: /global/IndexImmediateQuotedPrice/ (Caused by SSLError(SSLError(“bad handshake: SysCallError(-1, ‘Unexpected EOF’)”,),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File “D:/projects/DailyReport/scripts/test/test_requests.py”, line 9, in <module> r = requests.get(url) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\requests\api.py”, line 72, in get return request(‘get’, url, params=params, **kwargs) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\requests\api.py”, line 58, in request return session.request(method=method, url=url, **kwargs) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\requests\sessions.py”, line 508, in request resp = self.send(prep, **send_kwargs) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\requests\sessions.py”, line 618, in send r = adapter.send(request, **kwargs) File “C:\ProgramData\Anaconda3\envs\p36\lib\site-packages\requests\adapters.py”, line 506, in send raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host=‘www.cnyes.com’, port=443): Max retries exceeded with url: /global/IndexImmediateQuotedPrice/ (Caused by SSLError(SSLError(“bad handshake: SysCallError(-1, ‘Unexpected EOF’)”,),))
Some Information on Security Panel of Google Chrome DevTools
I use DevTools to Inspect www.cnyes.com:
Connection Protocol TLS 1.0 Key exchange RSA Cipher 3DES_EDE_CBC with HMAC-SHA1
Refer to the red circle on attach image.
Firefox Developer Tools shows Cipher suite: TLS_RSA_WITH_3DES_EDE_CBC_SHA
System Information
$ python -m requests.help
{
"chardet": {
"version": "3.0.4"
},
"cryptography": {
"version": "2.2.2"
},
"idna": {
"version": "2.6"
},
"implementation": {
"name": "CPython",
"version": "3.6.5"
},
"platform": {
"release": "8.1",
"system": "Windows"
},
"pyOpenSSL": {
"openssl_version": "1010008f",
"version": "17.5.0"
},
"requests": {
"version": "2.18.4"
},
"system_ssl": {
"version": "100020bf"
},
"urllib3": {
"version": "1.22"
},
"using_pyopenssl": true
}
Windows 8.1 Python 3.6.5 pip install request[security]
pip list Package Version
asn1crypto 0.24.0 certifi 2018.4.16 cffi 1.11.5 chardet 3.0.4 cryptography 2.2.2 idna 2.6 pip 10.0.1 pycparser 2.18 pyOpenSSL 17.5.0 requests 2.18.4 setuptools 39.1.0 six 1.11.0 urllib3 1.22 wheel 0.31.0 wincertstore 0.2
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
@fygul, so this server is in a pretty sad state (ssl labs report). It’s primary cipher suites are
RC4-MD5
andRC4-SHA
which aren’t secure and it supports 3DES_EDE_CBC with HMAC-SHA1 with TLS1.0 to appease browsers. If you change the cipher string to onlyCIPHERS = 'DES-CBC3-SHA'
it will connect, so there’s something else in the cipher string that the server is hanging on.Since this isn’t supported with Requests default cipher suite and there’s a path forward for debugging, I’m going to close this out.
@wty1143, I’d suggest taking a look at your cipher string and seeing if this fixes your issue. If not, you can either use your browsers developer tools or
openssl s_client -connect yourdomainhere.com:443
to determine what cipher suite is being negotiated.@nateprewitt I also have tried the method you mentioned, but none of them fixed this issue. However, when I tested the same code with my old version requests (2.0.1 I think) with old version urllib3, the issue was gone.
So I am wondering what’s the critical difference between these two versions and why the manual cipher solution did not work well in this case.
Again, thanks for your help.