jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/748375 )
Change subject: [IMPR] raise urllib3 NewConnectionError immediately ......................................................................
[IMPR] raise urllib3 NewConnectionError immediately
- urllib3 NewConnectionError with Errno -2 and 11001 never retries to establish the connection. - raise ConnectionError instead of requests.ConnectionError in that case
Bug: T297994 Change-Id: I43abe3417435489e2d737bbe3aec409a76f12a64 --- M pywikibot/comms/http.py M pywikibot/data/api.py M tests/http_tests.py 3 files changed, 9 insertions(+), 3 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index b248ff7..08099a0 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -291,6 +291,12 @@ if SSL_CERT_VERIFY_FAILED_MSG in str(response): raise FatalServerError(str(response))
+ if isinstance(response, requests.ConnectionError): + msg = str(response) + if 'NewConnectionError' in msg \ + and re.search(r'[Errno (-2|11001)]', msg): + raise ConnectionError(response) + if isinstance(response, Exception): with suppress(Exception): # request exception may contain response and request attribute diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index acde07e..9e6f8e3 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -1496,7 +1496,7 @@ pywikibot.warning('Caught HTTP 414 error, although not ' 'using GET.') raise - except FatalServerError: + except (ConnectionError, FatalServerError): # This error is not going to be fixed by just waiting pywikibot.error(traceback.format_exc()) raise diff --git a/tests/http_tests.py b/tests/http_tests.py index 246e225..36f07f9 100644 --- a/tests/http_tests.py +++ b/tests/http_tests.py @@ -1,6 +1,6 @@ """Tests for http module.""" # -# (C) Pywikibot team, 2014-2021 +# (C) Pywikibot team, 2014-2022 # # Distributed under the terms of the MIT license. # @@ -143,7 +143,7 @@ def test_server_not_found(self): """Test server not found exception.""" with self.assertRaisesRegex( - requests.exceptions.ConnectionError, + ConnectionError, 'Max retries exceeded with url: /w/api.php'): http.fetch('http://ru-sib.wikipedia.org/w/api.php', default_error_handling=True)
pywikibot-commits@lists.wikimedia.org