|
36 | 36 | B2ConnectionError, |
37 | 37 | B2Error, |
38 | 38 | B2RequestTimeout, |
39 | | - B2RequestTimeoutDuringUpload, |
40 | 39 | BadDateFormat, |
41 | 40 | BrokenPipe, |
42 | 41 | ClockSkew, |
@@ -254,7 +253,7 @@ def request( |
254 | 253 | :param url: a URL to call |
255 | 254 | :param headers: headers to send. |
256 | 255 | :param data: raw bytes or a file-like object to send |
257 | | - :param try_count: a number of retries |
| 256 | + :param try_count: a number of attempts |
258 | 257 | :param params: a dict that will be converted to query string for GET requests or additional metadata for POST requests |
259 | 258 | :param stream: if True, the response will be streamed |
260 | 259 | :param _timeout: a timeout for the request in seconds if not default |
@@ -355,14 +354,9 @@ def post_content_return_json( |
355 | 354 | :param data: a file-like object to send |
356 | 355 | :return: a dict that is the decoded JSON |
357 | 356 | """ |
358 | | - try: |
359 | | - return self.request_content_return_json( |
360 | | - 'POST', url, headers, data, try_count, post_params, _timeout=_timeout |
361 | | - ) |
362 | | - except B2RequestTimeout: |
363 | | - # this forces a token refresh, which is necessary if request is still alive |
364 | | - # on the server but has terminated for some reason on the client. See #79 |
365 | | - raise B2RequestTimeoutDuringUpload() |
| 357 | + return self.request_content_return_json( |
| 358 | + 'POST', url, headers, data, try_count, post_params, _timeout=_timeout |
| 359 | + ) |
366 | 360 |
|
367 | 361 | def post_json_return_json(self, url, headers, params, try_count: int = TRY_COUNT_OTHER): |
368 | 362 | """ |
@@ -423,7 +417,7 @@ def get_content(self, url, headers, try_count: int = TRY_COUNT_DOWNLOAD): |
423 | 417 |
|
424 | 418 | :param str url: a URL to call |
425 | 419 | :param dict headers: headers to send |
426 | | - :param int try_count: a number or retries |
| 420 | + :param int try_count: a number of attempts |
427 | 421 | :return: Context manager that returns an object that supports iter_content() |
428 | 422 | """ |
429 | 423 | response = self.request( |
@@ -456,7 +450,7 @@ def head_content( |
456 | 450 |
|
457 | 451 | :param str url: a URL to call |
458 | 452 | :param dict headers: headers to send |
459 | | - :param int try_count: a number or retries |
| 453 | + :param int try_count: a number of attempts |
460 | 454 | :return: HTTP response |
461 | 455 | """ |
462 | 456 | return self.request('HEAD', url, headers=headers, try_count=try_count) |
@@ -586,9 +580,13 @@ def _translate_and_retry( |
586 | 580 | the exception is a retryable B2Error. |
587 | 581 |
|
588 | 582 | :param fcn: request function to call |
589 | | - :param try_count: a number of retries |
| 583 | + :param try_count: a number of attempts |
590 | 584 | :param post_params: request parameters |
591 | 585 | """ |
| 586 | + |
| 587 | + if try_count < 1: |
| 588 | + raise ValueError('try_count must be >= 1') |
| 589 | + |
592 | 590 | # For all but the last try, catch the exception. |
593 | 591 | wait_time = 1.0 |
594 | 592 | max_wait_time = 64 |
|
0 commit comments