velvet.logging_retry
Documentation for eth_defi.velvet.logging_retry Python module.
Loggable Retry() adapter for requests package
Classes
In the case we need to throttle Coingecko or other HTTP API, be verbose about it. |
- class LoggingRetry
Bases:
urllib3.util.retry.RetryIn the case we need to throttle Coingecko or other HTTP API, be verbose about it.
Example how to use:
from requests.sessions import HTTPAdapter # Set up dealing with network connectivity flakey if retry_policy is None: # https://stackoverflow.com/a/35504626/315168 retry_policy = LoggingRetry( total=5, backoff_factor=0.1, status_forcelist=[429, 500, 502, 503, 504], ) session.mount("http://", HTTPAdapter(max_retries=retry_policy)) session.mount("https://", HTTPAdapter(max_retries=retry_policy))
- __init__(*args, **kwargs)
- increment(method=None, url=None, response=None, error=None, _pool=None, _stacktrace=None)
Return a new Retry object with incremented retry counters.
- Parameters
response (
BaseHTTPResponse) – A response object, or None, if the server did not return a response.error (Exception) – An error encountered during the request, or None if the response was received successfully.
- Returns
A new
Retryobject.
- classmethod from_int(retries, redirect=True, default=None)
Backwards-compatibility for the old retries format.
- get_retry_after(response)
Get the value of Retry-After in seconds.
- Parameters
response (BaseHTTPResponse) –
- Return type
float | None
- is_retry(method, status_code, has_retry_after=False)
Is this method/status code retryable? (Based on allowlists and control variables such as the number of total retries to allow, whether to respect the Retry-After header, whether this header is present, and whether the returned status code is on the list of status codes to be retried upon on the presence of the aforementioned header)
- sleep(response=None)
Sleep between retry attempts.
This method will respect a server’s
Retry-Afterresponse header and sleep the duration of the time requested. If that is not present, it will use an exponential backoff. By default, the backoff factor is 0 and this method will return immediately.- Parameters
response (BaseHTTPResponse | None) –
- Return type
None