Retry not being applied to ECONNRESET in pyopenssl
See original GitHub issueWe have this retry policy in a requests usage of urllib3:
from requests import Response, Session
from requests.adapters import HTTPAdapter
from urllib3 import Retry
session = Session()
retry_count = 3
retry = Retry(
total=retry_count,
read=retry_count,
connect=retry_count,
backoff_factor=0.3,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
However, ECONNRESET
such as the following don’t appear to be retried:
Traceback (most recent call last):
--
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib64/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/lib64/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib64/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 296, in recv_into
return self.recv_into(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 285, in recv_into
raise SocketError(str(e))
OSError: (104, 'ECONNRESET')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
_stacktrace=sys.exc_info()[2])
File "/usr/lib/python3.6/site-packages/urllib3/util/retry.py", line 357, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/usr/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 387, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib64/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/lib64/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib64/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 296, in recv_into
return self.recv_into(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 285, in recv_into
raise SocketError(str(e))
urllib3.exceptions.ProtocolError: ('Connection aborted.', OSError("(104, 'ECONNRESET')",))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/awacs_tools/client.py", line 91, in request
response = self.session.request(method, url, timeout=timeout, **kw)
File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 490, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', OSError("(104, 'ECONNRESET')",))
Are we doing something wrong or is this a bug somewhere?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Is there any possibility to retry only Python low-level urllib3 ...
I see no any possible way to have retry on this error, even with the urllib3's util.Retry class debugging the used libs themselves...
Read more >I cannot connect and access DSS REST API through Python ...
Hi,. I am trying to use Python to access DSS REST API and I got the result all time correctly. But in recent...
Read more >snowflake-connector-python 1.6.8 - PyPI
Fixed hang if the connection is not explicitly closed since 1.6.4. ... Added retry OpenSSL low level errors ETIMEDOUT and ECONNRESET.
Read more >Bad Handshake on Pythoon Client. - Visa Developer Community
I have been able to access the API in Postman. However, I am still not able to access it Python. I wrote a...
Read more >TrueNAS fails to install update to U2 saying package not found
I am currently getting this error when tring to update TrueNAS U1 to TrueNAS U2. The package that it is downloading persists between...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So we import
socket.error
asSocketError
and then catch it to handle retries with. In our pyopenssl compatibility, we raise SocketError after importing it.As you can see from your traceback, that should be getting handled (the exception is originating in
getresponse()
in_make_response
). Of course, we have no clue what versions of urllib3 and requests you’re using, so perhaps the code we’re referencing isn’t relevant to that version. Additionally, we have no clue what you’re actual request looks like. So there could be several things wrong here:At this point, this is a discussion for StackOverflow because it’s not a bug in urllib3 (or requests).
Cheers, Ian
I have the same issue. Unfortunately I cannot provide part of my code. I use it to get table from a website which is then used and then I no longer use the library. It’s one of the set up steps in my code. Then I have different thing which does not include using urllib3. I have Python 3.7.3, urrllib3 version 1.24.1, i run my code on Raspberry Pi and I tried it on Ubuntu 16.04.6. Both OSs have the same issue 104 but the message is slightly different.