init_requests_session¶
- pyhelpers.ops.init_requests_session(url, max_retries=5, backoff_factor=0.1, retry_status='default', **kwargs)[source]¶
Instantiate a requests session with configurable retry behaviour.
- Parameters:
url (str) – A valid URL to establish the session.
max_retries (int) – Maximum number of retry attempts; defaults to
5
.backoff_factor (float) – Backoff factor for exponential backoff in retries; defaults to
0.1
.retry_status – HTTP status codes that trigger retries, derived from urllib3.util.Retry(); defaults to
[429, 500, 502, 503, 504]
whenretry_status='default'
.kwargs – [Optional] Additional parameters for the class urllib3.util.Retry().
- Returns:
A requests.Session() instance configured with the specified retry settings.
- Return type:
requests.Session
Examples:
>>> from pyhelpers.ops import init_requests_session >>> url = 'https://www.python.org/static/community_logos/python-logo-master-v3-TM.png' >>> s = init_requests_session(url) >>> type(s) requests.sessions.Session