aiohttp-retry is a simple retry client for aiohttp, providing robust request retrying capabilities for asynchronous HTTP operations. It supports various retry strategies like exponential backoff and random delays. The current version is 2.9.1 and it requires Python 3.7 or higher. The library is actively maintained with regular releases addressing bug fixes and introducing new features.
pip install aiohttp-retryVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `RetryClient` with `ExponentialRetry` options and make a GET request. The `raise_for_status=False` parameter is often used to ensure that aiohttp-retry's retry logic can intercept and handle HTTP error responses instead of aiohttp immediately raising an exception. The example attempts to hit a 500 status endpoint, which should trigger the retry mechanism.
Review the official documentation and examples for versions 2.0+ to adapt your code. Consider `pip install aiohttp-retry==1.2` if you cannot upgrade.
Upgrade to version 2.8.3 or higher (e.g., 2.9.1) to get the fix.
Update your custom `get_timeout` signature to `def get_timeout(self, attempt_num: int, response: ClientResponse | None = None) -> float:`
Ensure `start_timeout` and `factor` are set to appropriate non-zero values to introduce delays between retry attempts.
To customize 5xx behavior: `RetryClient(retry_all_server_errors=False, retry_options=RetryOptions(statuses={500, 503}))`Remove the `retry_attempts` keyword argument from any calls where it is being used. To specify the total number of attempts (including the initial request), configure it via `RetryOptions` by setting the `attempts` parameter (e.g., `RetryOptions(attempts=3)`).
Ensure 'aiohttp' is installed in the correct environment by running 'python3.6 -m pip install aiohttp'.
Implement error handling to manage unexpected content types and consider retrying the request upon failure.
Verify the URL and network connectivity; consider implementing retries with exponential backoff for transient errors.
Install the library using pip: `pip install aiohttp-retry`
Instead of `retry_attempts`, configure the number of attempts via `RetryOptions` and pass it to the `RetryClient` constructor or the request method. For example: `from aiohttp_retry import RetryClient, ExponentialRetry; retry_options = ExponentialRetry(attempts=3); retry_client = RetryClient(retry_options=retry_options)` or `async with retry_client.get(url, retry_options=ExponentialRetry(attempts=3))`.