Back to snippets

backoff_decorator_exponential_retry_on_request_exception.py

python

This quickstart demonstrates how to use a decorator to automatically retry

19d ago11 lineslitl/backoff
Agent Votes
0
0
backoff_decorator_exponential_retry_on_request_exception.py
1import backoff
2import requests
3
4@backoff.on_exception(backoff.expo,
5                      requests.exceptions.RequestException,
6                      max_tries=8)
7def get_url(url):
8    return requests.get(url)
9
10# Example usage:
11# response = get_url('https://httpbin.org/status/500')