Backoff session for requests
resp = BackoffSession().get('https://...')By default, BackoffSession tries before giving up until any following condition is met:
- Tries 10 times
- Reaches 20 seconds
- Meets
requests.RequestException - Meets HTTP client error (4xx)
Behaviors above can be customized with parameters.
BackoffSession(
exception=(RequestException, ValueError), # Give up when ValueError occurs, too.
max_tries=100, # Tries 100 times before giving up
max_time=300, # Wait until maximum 300 seconds before giving up
giveup=lambda e: e.response.text == 'You're fired!' # Give up when specific response is met
)BackoffSession heavily depends on backoff package.
spoqa-requests-backoff is distributed under the terms of MIT License.
See LICENSE for more details.