download.retry_request()
Create a tenacity retry decorator for HTTP requests using the requests library.
Usage
download.retry_request(
logger,
*,
extra_status_codes=frozenset(),
)This decorator will automatically retry functions that make HTTP requests when they encounter transient network or server-side errors. It is a pre-configured tenacity.retry function with the following behaviors:
reraise=Trueto see encountered exception at the end of the stack trace- Retries
ConnectionErrorandTimeouterrors of therequestslibrary, as well as HTTP Errors 408, 429, 502, 503, 504 (plus any status codes passed viaextra_status_codes). - Maximum attempts: 3
- Wait strategy: Exponential backoff with jitter (the latter for resolving contention between multiple processes)
Parameters
logger: logging.Logger-
Logger instance used to log retry attempts before each sleep.
extra_status_codes: frozenset of int = frozenset()-
Additional HTTP status codes to treat as transient for this call site, on top of the codes in
TRANSIENT_HTTP_STATUS_CODES. Use this rather than wideningTRANSIENT_HTTP_STATUS_CODESitself when a status code (e.g. 500) is only known to be transient for one particular endpoint.
Returns
Callable[[WrappedFn], WrappedFn]- A tenacity retry decorator configured for HTTP request retries.