@@ -285,38 +285,27 @@ def sleep_for_retry(self, response: BaseHTTPResponse) -> bool:
285285 """
286286 retry_after = self .get_retry_after (response )
287287 if retry_after :
288- backoff = self .get_exponential_backoff ()
289- proposed_wait = max (backoff , retry_after )
290- self .check_proposed_wait (proposed_wait )
291- time .sleep (proposed_wait )
292- return True
288+ proposed_wait = retry_after
289+ else :
290+ proposed_wait = self .get_exponential_backoff ()
293291
294- return False
292+ proposed_wait = min (proposed_wait , self .delay_max )
293+ self .check_proposed_wait (proposed_wait )
294+ time .sleep (proposed_wait )
295+ return True
295296
296297 def get_exponential_backoff (self ) -> float :
297298 """
298299 This method implements the exponential backoff algorithm to calculate the delay between retries.
299- :return:
300- """
301-
302- current_attempt = self .stop_after_attempts_count - self .total
303- proposed_backoff = (2 ** current_attempt ) * self .delay_min
304- proposed_backoff = min (proposed_backoff , self .delay_max )
305- self .check_proposed_wait (proposed_backoff )
306-
307- return proposed_backoff
308-
309- def get_backoff_time (self ) -> float :
310- """Calls urllib3's built-in get_backoff_time.
311300
312301 Never returns a value larger than self.delay_max
313302 A MaxRetryDurationError will be raised if the calculated backoff would exceed self.max_attempts_duration
314303
315- Note: within urllib3, a backoff is only calculated in cases where a Retry-After header is not present
316- in the previous unsuccessful request and `self.respect_retry_after_header` is True (which is always true)
304+ :return:
317305 """
318306
319- proposed_backoff = super ().get_backoff_time ()
307+ current_attempt = self .stop_after_attempts_count - self .total
308+ proposed_backoff = (2 ** current_attempt ) * self .delay_min
320309 proposed_backoff = min (proposed_backoff , self .delay_max )
321310 self .check_proposed_wait (proposed_backoff )
322311
0 commit comments