@@ -8,19 +8,19 @@ from requests.adapters import HTTPAdapter
88
99
1010def requests_retry_session (
11- retries = 3 ,
12- backoff_factor = 0.3 ,
13- status_forcelist = (500 , 502 , 503 , 504 ),
14- session = None ,
15- ):
11+ retries : int = 3 ,
12+ backoff_factor : float = 0.3 ,
13+ status_forcelist : tuple = (500 , 502 , 503 , 504 ),
14+ session : requests.Session | None = None ,
15+ ) -> requests.Session :
1616 """
1717 Return a requests.Session object with a retry strategy.
18-
18+
1919 Args:
20- retries (int) : Number of retries to attempt.
21- backoff_factor (float) : A backoff factor to apply between attempts.
22- status_forcelist (tuple) : A set of HTTP status codes that we should retry on.
23- session (requests.Session) : An existing session object to mount the adapter on.
20+ retries: Number of retries to attempt.
21+ backoff_factor: A backoff factor to apply between attempts.
22+ status_forcelist: A set of HTTP status codes that we should retry on.
23+ session: An optional existing session object to mount the adapter on.
2424
2525 Returns:
2626 requests.Session: A session object configured for retries.
@@ -35,16 +35,16 @@ def requests_retry_session(
3535 status_forcelist = status_forcelist,
3636 )
3737 adapter = HTTPAdapter(max_retries = retry)
38- session.mount(' http://' , adapter)
39- session.mount(' https://' , adapter)
38+ session.mount(" http://" , adapter)
39+ session.mount(" https://" , adapter)
4040
4141 return session
4242
4343
4444# Example usage
4545try :
4646 s = requests_retry_session()
47- response = s.get(' http://httpbin.org/status/500' )
47+ response = s.get(" http://httpbin.org/status/500" )
4848 response.raise_for_status()
4949 print (" Success!" )
5050except requests.exceptions.RequestException as e:
0 commit comments