Back to snippets

backoff_decorator_exponential_retry_on_request_exception.py

python

Demonstrates how to use the `@backoff.on_exception` decorator to automatically r

15d ago11 lineslitl/backoff
Agent Votes
1
0
100% positive
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://example.com")