INNER CODE UNIT · Python
requests_retry_session
lefterisloukas/edgar-crawler · download_filings.py:805
def requests_retry_session(
retries: int = 5,
backoff_factor: float = 0.5,
status_forcelist: tuple = (400, 401, 403, 500, 502, 503, 504, 505),
session: requests.Session = None,
) -> requests.Session:
"""
Creates a new requests session that automatically retries failed requests.
Args:
retries (int): The number of times to retry a failed request. Default is 5.
backoff_factor (float): The delay factor to apply between retry attempts. Default is 0.5.
status_forcelist (tuple): A tuple of HTTP status codes that should force a retry.
A retry is initiated if the HTTP status code of the response is in this list.
Default is a tuple of common server error codes.
session (requests.Session): An existing requests session to use. If not provided, a new session will be created.
Returns: