| id | retries |
|---|---|
| title | Retries |
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import CodeBlock from '@theme/CodeBlock';
import ApiLink from '@theme/ApiLink';
import RetriesAsyncExample from '!!raw-loader!./code/05_retries_async.py'; import RetriesSyncExample from '!!raw-loader!./code/05_retries_sync.py';
When dealing with network communication, failures can occasionally occur. The Apify client automatically retries requests that fail due to:
- Network errors
- Internal errors in the Apify API (HTTP status codes 500 and above)
- Rate limit errors (HTTP status code 429)
By default, the client will retry a failed request up to 8 times. The retry intervals use an exponential backoff strategy:
- The first retry occurs after approximately 500 milliseconds.
- The second retry occurs after approximately 1,000 milliseconds, and so on.
You can customize this behavior using the following options in the ApifyClient constructor:
max_retries: Defines the maximum number of retry attempts.min_delay_between_retries_millis: Sets the minimum delay between retries (in milliseconds).
Retries with exponential backoff are a common strategy for handling network errors. They help to reduce the load on the server and increase the chances of a successful request.
{RetriesAsyncExample} {RetriesSyncExample}