LoggingRetry
Documentation for eth_defi.velvet.logging_retry.LoggingRetry Python class.
- 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))
Attributes summary
DEFAULTDEFAULT_ALLOWED_METHODSDEFAULT_BACKOFF_MAXDEFAULT_REMOVE_HEADERS_ON_REDIRECTDEFAULT_RETRY_AFTER_MAXRETRY_AFTER_STATUS_CODESMethods summary
__init__(*args, **kwargs)from_int(retries[, redirect, default])Backwards-compatibility for the old retries format.
Formula for computing the current backoff
get_retry_after(response)Get the value of Retry-After in seconds.
increment([method, url, response, error, ...])Return a new Retry object with incremented retry counters.
Are we out of retries?
is_retry(method, status_code[, has_retry_after])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)
new(**kw)parse_retry_after(retry_after)sleep([response])Sleep between retry attempts.
sleep_for_retry(response)- __init__(*args, **kwargs)
- classmethod from_int(retries, redirect=True, default=None)
Backwards-compatibility for the old retries format.
- get_backoff_time()
Formula for computing the current backoff
- Return type
- get_retry_after(response)
Get the value of Retry-After in seconds.
- Parameters
response (BaseHTTPResponse) –
- Return type
float | None
- 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.
- is_exhausted()
Are we out of retries?
- Return type
- 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