diff --git a/tests/test_fetcher_ng.py b/tests/test_fetcher_ng.py index 434c62a2..03cb33f3 100644 --- a/tests/test_fetcher_ng.py +++ b/tests/test_fetcher_ng.py @@ -109,7 +109,11 @@ 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.TimeoutError} + attr = {"stream.side_effect": urllib3.exceptions.MaxRetryError( + urllib3.connectionpool.ConnectionPool("localhost"), + "", + urllib3.exceptions.TimeoutError(), + )} mock_response.configure_mock(**attr) mock_session_get.return_value = mock_response diff --git a/tuf/ngclient/_internal/urllib3_fetcher.py b/tuf/ngclient/_internal/urllib3_fetcher.py index 85cc80d5..8c2a2ff6 100644 --- a/tuf/ngclient/_internal/urllib3_fetcher.py +++ b/tuf/ngclient/_internal/urllib3_fetcher.py @@ -103,8 +103,9 @@ def _chunks( try: yield from response.stream(self.chunk_size) - 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 finally: response.release_conn()