Pause execution if a response has a 429 status TOO_MANY_REQUEST. for the number of seconds indicated in the 'Retry-After' header, or 60 seconds if this header is missing. Retry the failed request afterwards.
(self, response: Response)
| 323 | |
| 324 | @response_hook |
| 325 | def pause_if_too_many_requests(self, response: Response): |
| 326 | """ |
| 327 | Pause execution if a response has a 429 status TOO_MANY_REQUEST. |
| 328 | for the number of seconds indicated in the 'Retry-After' header, |
| 329 | or 60 seconds if this header is missing. |
| 330 | Retry the failed request afterwards. |
| 331 | """ |
| 332 | if response.status == HTTPStatus.TOO_MANY_REQUESTS: |
| 333 | retry_after = response.headers.get('Retry-After', 60) |
| 334 | logger.warning(f'Got TOO_MANY_REQUESTS response, sleep {int(retry_after)} seconds') |
| 335 | time.sleep(retry_after) |
| 336 | return self.send(response.request) |
| 337 | return response |
| 338 | |
| 339 | @response_hook |
| 340 | def handle_error(self, response): |