Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions b2sdk/_internal/b2http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+timeout_error.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix TimeoutError handling in `b2http`.
12 changes: 12 additions & 0 deletions test/unit/b2http/test_b2http.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from apiver_deps import USER_AGENT, B2Http, B2HttpApiConfig, ClockSkewHook
from apiver_deps_exception import (
B2ConnectionError,
B2RequestTimeout,
BadDateFormat,
BadJson,
BadRequest,
Expand Down Expand Up @@ -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')
Expand Down
Loading