From d5fd7755726f4b283caed836b37cc0db83f5f96a Mon Sep 17 00:00:00 2001 From: Olzhas Arystanov Date: Wed, 23 Apr 2025 17:38:40 +0700 Subject: [PATCH 1/2] Fix TimeoutError handling in `b2http` --- b2sdk/_internal/b2http.py | 6 ++++-- changelog.d/+timeout_error.fixed.md | 1 + test/unit/b2http/test_b2http.py | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 changelog.d/+timeout_error.fixed.md diff --git a/b2sdk/_internal/b2http.py b/b2sdk/_internal/b2http.py index 4044a1014..2f0df66a7 100644 --- a/b2sdk/_internal/b2http.py +++ b/b2sdk/_internal/b2http.py @@ -545,14 +545,16 @@ def _translate_errors(cls, fcn, post_params=None): raise UnknownHost() elif isinstance(e1, requests.packages.urllib3.exceptions.ProtocolError): e2 = e1.args[1] + + if isinstance(e2, TimeoutError): + raise B2RequestTimeout(str(e0)) + if isinstance(e2, socket.error): if len(e2.args) >= 2 and e2.args[1] == 'Broken pipe': # Broken pipes are usually caused by the service rejecting # an upload request for cause, so we use a 400 Bad Request # code. raise BrokenPipe() - elif isinstance(e2, TimeoutError): - raise B2RequestTimeout(str(e0)) raise B2ConnectionError(str(e0)) except requests.Timeout as e: diff --git a/changelog.d/+timeout_error.fixed.md b/changelog.d/+timeout_error.fixed.md new file mode 100644 index 000000000..6423e4a5f --- /dev/null +++ b/changelog.d/+timeout_error.fixed.md @@ -0,0 +1 @@ +Fix TimeoutError handling in `b2http`. diff --git a/test/unit/b2http/test_b2http.py b/test/unit/b2http/test_b2http.py index 7f3020c51..28ab4dad5 100644 --- a/test/unit/b2http/test_b2http.py +++ b/test/unit/b2http/test_b2http.py @@ -20,6 +20,7 @@ from apiver_deps import USER_AGENT, B2Http, B2HttpApiConfig, ClockSkewHook from apiver_deps_exception import ( B2ConnectionError, + B2RequestTimeout, BadDateFormat, BadJson, BadRequest, @@ -80,6 +81,17 @@ def fcn(): with pytest.raises(UnknownHost): B2Http._translate_errors(fcn) + def test_request_timeout(self): + def fcn(): + raise requests.ConnectionError( + requests.packages.urllib3.exceptions.ProtocolError( + 'dummy', TimeoutError('The write operation timed out') + ) + ) + + with pytest.raises(B2RequestTimeout): + B2Http._translate_errors(fcn) + def test_connection_error(self): def fcn(): raise requests.ConnectionError('a message') From e2c4804bfd949736e6752635745ca52f0e556f41 Mon Sep 17 00:00:00 2001 From: Olzhas Arystanov Date: Thu, 24 Apr 2025 01:50:05 +0700 Subject: [PATCH 2/2] release 2.8.1 --- CHANGELOG.md | 12 ++++++++++++ changelog.d/+timeout_error.fixed.md | 1 - changelog.d/532.doc.md | 1 - 3 files changed, 12 insertions(+), 2 deletions(-) delete mode 100644 changelog.d/+timeout_error.fixed.md delete mode 100644 changelog.d/532.doc.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c77d282..283afeca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,18 @@ upcoming release can be found in [changelog.d](changelog.d). +## [2.8.1](https://github.com/Backblaze/b2-sdk-python/releases/tag/v2.8.1) - 2025-04-24 + + +### Fixed + +- Fix TimeoutError handling in `b2http`. + +### Doc + +- Document params in FileRetentionSetting class. ([#532](https://github.com/Backblaze/b2-sdk-python/issues/532)) + + ## [2.8.0](https://github.com/Backblaze/b2-sdk-python/releases/tag/v2.8.0) - 2025-01-23 diff --git a/changelog.d/+timeout_error.fixed.md b/changelog.d/+timeout_error.fixed.md deleted file mode 100644 index 6423e4a5f..000000000 --- a/changelog.d/+timeout_error.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Fix TimeoutError handling in `b2http`. diff --git a/changelog.d/532.doc.md b/changelog.d/532.doc.md deleted file mode 100644 index 9dc826694..000000000 --- a/changelog.d/532.doc.md +++ /dev/null @@ -1 +0,0 @@ -Document params in FileRetentionSetting class.