Skip to content

Commit 91a2e9e

Browse files
committed
Fix type error in 429 retrying behavior with Retry-After header
1 parent a38bc89 commit 91a2e9e

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

b2sdk/_internal/exception.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ def __str__(self):
452452
class TooManyRequests(B2Error):
453453
def __init__(self, retry_after_seconds=None):
454454
super().__init__()
455-
self.retry_after_seconds = retry_after_seconds
455+
456+
self.retry_after_seconds = int(retry_after_seconds)
456457

457458
def __str__(self):
458459
return 'Too many requests'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix type error in retrying behavior for 429 status with Retry-After header value set.

test/unit/b2http/test_b2http.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ def test_never_works(self, b2_http: B2Http, mock_time: MagicMock):
337337

338338
assert mock_time.mock_calls == [call(1.0), call(1.5)]
339339

340-
@pytest.mark.xfail(reason='no int conversion in the retry-after header parsing logic')
341340
@responses.activate
342341
def test_too_many_requests_works_after_sleep(self, b2_http: B2Http, mock_time: MagicMock):
343342
_mock_error_response(self.URL, status=429, headers={'Retry-After': '2'})
@@ -346,7 +345,6 @@ def test_too_many_requests_works_after_sleep(self, b2_http: B2Http, mock_time: M
346345
b2_http.request(responses.GET, self.URL, {})
347346
mock_time.assert_called_once_with(2)
348347

349-
@pytest.mark.xfail(reason='no int conversion in the retry-after header parsing logic')
350348
@responses.activate
351349
def test_too_many_requests_failed_after_sleep(self, b2_http: B2Http, mock_time: MagicMock):
352350
_mock_error_response(self.URL, status=429, headers={'Retry-After': '2'})
@@ -356,7 +354,6 @@ def test_too_many_requests_failed_after_sleep(self, b2_http: B2Http, mock_time:
356354
b2_http.request(responses.GET, self.URL, {}, try_count=2)
357355
mock_time.assert_called_once_with(2)
358356

359-
@pytest.mark.xfail(reason='no int conversion in the retry-after header parsing logic')
360357
@responses.activate
361358
def test_too_many_requests_retry_header_combination_one(
362359
self, b2_http: B2Http, mock_time: MagicMock
@@ -370,7 +367,6 @@ def test_too_many_requests_retry_header_combination_one(
370367
b2_http.request(responses.GET, self.URL, {}, try_count=4)
371368
assert mock_time.mock_calls == [call(2), call(1.5), call(2)]
372369

373-
@pytest.mark.xfail(reason='no int conversion in the retry-after header parsing logic')
374370
@responses.activate
375371
def test_too_many_requests_retry_header_combination_two(
376372
self, b2_http: B2Http, mock_time: MagicMock

0 commit comments

Comments
 (0)