3636 B2ConnectionError ,
3737 B2Error ,
3838 B2RequestTimeout ,
39- B2RequestTimeoutDuringUpload ,
4039 BadDateFormat ,
4140 BrokenPipe ,
4241 ClockSkew ,
4342 ConnectionReset ,
4443 PotentialS3EndpointPassedAsRealm ,
44+ ServiceError ,
4545 UnknownError ,
4646 UnknownHost ,
4747 interpret_b2_error ,
@@ -281,7 +281,7 @@ def do_request():
281281 self ._run_post_request_hooks (method , url , request_headers , response )
282282 return response
283283
284- return self ._translate_and_retry (do_request , try_count , params )
284+ return self ._translate_and_retry (do_request , try_count , method , request_headers , params )
285285
286286 def request_content_return_json (
287287 self ,
@@ -355,14 +355,9 @@ def post_content_return_json(
355355 :param data: a file-like object to send
356356 :return: a dict that is the decoded JSON
357357 """
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 ()
358+ return self .request_content_return_json (
359+ 'POST' , url , headers , data , try_count , post_params , _timeout = _timeout
360+ )
366361
367362 def post_json_return_json (self , url , headers , params , try_count : int = TRY_COUNT_OTHER ):
368363 """
@@ -579,7 +574,12 @@ def _translate_errors(cls, fcn, post_params=None):
579574
580575 @classmethod
581576 def _translate_and_retry (
582- cls , fcn : Callable , try_count : int , post_params : dict [str , Any ] | None = None
577+ cls ,
578+ fcn : Callable ,
579+ try_count : int ,
580+ method : str ,
581+ headers : dict [str , Any ],
582+ post_params : dict [str , Any ] | None = None ,
583583 ):
584584 """
585585 Try calling fcn try_count times, retrying only if
@@ -598,6 +598,15 @@ def _translate_and_retry(
598598 except B2Error as e :
599599 if not e .should_retry_http ():
600600 raise
601+ if (
602+ method == 'POST'
603+ and 'X-Bz-Content-Sha1' in headers
604+ and isinstance (e , (ServiceError , B2RequestTimeout ))
605+ ):
606+ # This is an upload operation, so we avoid http-level retries
607+ # here to force an upload token refresh
608+ raise
609+
601610 logger .debug (str (e ), exc_info = True )
602611 if e .retry_after_seconds is not None :
603612 sleep_duration = e .retry_after_seconds
0 commit comments