Skip to content

Commit d5fd775

Browse files
committed
Fix TimeoutError handling in b2http
1 parent 9ee87a0 commit d5fd775

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

b2sdk/_internal/b2http.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -545,14 +545,16 @@ def _translate_errors(cls, fcn, post_params=None):
545545
raise UnknownHost()
546546
elif isinstance(e1, requests.packages.urllib3.exceptions.ProtocolError):
547547
e2 = e1.args[1]
548+
549+
if isinstance(e2, TimeoutError):
550+
raise B2RequestTimeout(str(e0))
551+
548552
if isinstance(e2, socket.error):
549553
if len(e2.args) >= 2 and e2.args[1] == 'Broken pipe':
550554
# Broken pipes are usually caused by the service rejecting
551555
# an upload request for cause, so we use a 400 Bad Request
552556
# code.
553557
raise BrokenPipe()
554-
elif isinstance(e2, TimeoutError):
555-
raise B2RequestTimeout(str(e0))
556558
raise B2ConnectionError(str(e0))
557559

558560
except requests.Timeout as e:

changelog.d/+timeout_error.fixed.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix TimeoutError handling in `b2http`.

test/unit/b2http/test_b2http.py

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from apiver_deps import USER_AGENT, B2Http, B2HttpApiConfig, ClockSkewHook
2121
from apiver_deps_exception import (
2222
B2ConnectionError,
23+
B2RequestTimeout,
2324
BadDateFormat,
2425
BadJson,
2526
BadRequest,
@@ -80,6 +81,17 @@ def fcn():
8081
with pytest.raises(UnknownHost):
8182
B2Http._translate_errors(fcn)
8283

84+
def test_request_timeout(self):
85+
def fcn():
86+
raise requests.ConnectionError(
87+
requests.packages.urllib3.exceptions.ProtocolError(
88+
'dummy', TimeoutError('The write operation timed out')
89+
)
90+
)
91+
92+
with pytest.raises(B2RequestTimeout):
93+
B2Http._translate_errors(fcn)
94+
8395
def test_connection_error(self):
8496
def fcn():
8597
raise requests.ConnectionError('a message')

0 commit comments

Comments
 (0)