diff --git a/tests/test_fetcher_ng.py b/tests/test_fetcher_ng.py index 5c6de0f83e..434c62a233 100644 --- a/tests/test_fetcher_ng.py +++ b/tests/test_fetcher_ng.py @@ -109,11 +109,7 @@ def test_http_error(self) -> None: def test_response_read_timeout(self, mock_session_get: Mock) -> None: mock_response = Mock() mock_response.status = 200 - attr = { - "stream.side_effect": urllib3.exceptions.ConnectionError( - "Simulated timeout" - ) - } + attr = {"stream.side_effect": urllib3.exceptions.TimeoutError} mock_response.configure_mock(**attr) mock_session_get.return_value = mock_response @@ -125,7 +121,11 @@ def test_response_read_timeout(self, mock_session_get: Mock) -> None: @patch.object( urllib3.PoolManager, "request", - side_effect=urllib3.exceptions.TimeoutError, + side_effect=urllib3.exceptions.MaxRetryError( + urllib3.connectionpool.ConnectionPool("localhost"), + "", + urllib3.exceptions.TimeoutError(), + ), ) def test_session_get_timeout(self, mock_session_get: Mock) -> None: with self.assertRaises(exceptions.SlowRetrievalError): diff --git a/tuf/ngclient/_internal/urllib3_fetcher.py b/tuf/ngclient/_internal/urllib3_fetcher.py index f2c9b4f176..85cc80d5fb 100644 --- a/tuf/ngclient/_internal/urllib3_fetcher.py +++ b/tuf/ngclient/_internal/urllib3_fetcher.py @@ -79,8 +79,9 @@ def _fetch(self, url: str) -> Iterator[bytes]: preload_content=False, timeout=urllib3.Timeout(self.socket_timeout), ) - except urllib3.exceptions.TimeoutError as e: - raise exceptions.SlowRetrievalError from e + except urllib3.exceptions.MaxRetryError as e: + if isinstance(e.reason, urllib3.exceptions.TimeoutError): + raise exceptions.SlowRetrievalError from e if response.status >= 400: response.close() @@ -102,10 +103,7 @@ def _chunks( try: yield from response.stream(self.chunk_size) - except ( - urllib3.exceptions.ConnectionError, - urllib3.exceptions.TimeoutError, - ) as e: + except urllib3.exceptions.TimeoutError as e: raise exceptions.SlowRetrievalError from e finally: