mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-07 07:13:17 +08:00
This also removes the outdated comments around authorship of each file. If there is still interest in this information, one can just look at the git history.
31 lines
800 B
Python
31 lines
800 B
Python
# -*- coding: utf-8 -*-
|
|
# SPDX-License-Identifier: MIT
|
|
import requests
|
|
from requests.packages.urllib3.util.retry import Retry
|
|
|
|
|
|
def get_requests_session(auth=False):
|
|
"""
|
|
Create a requests session with retries configured.
|
|
|
|
:return: the configured requests session
|
|
:rtype: requests.Session
|
|
"""
|
|
session = requests.Session()
|
|
retry = Retry(
|
|
total=3,
|
|
read=3,
|
|
connect=3,
|
|
backoff_factor=0.5,
|
|
status_forcelist=(500, 502, 503, 504),
|
|
)
|
|
retry.BACKOFF_MAX = 2
|
|
adapter = requests.adapters.HTTPAdapter(max_retries=retry)
|
|
session.mount("http://", adapter)
|
|
session.mount("https://", adapter)
|
|
return session
|
|
|
|
|
|
# TODO: Use this instead of requests.get directly throughout the codebase
|
|
requests_session = get_requests_session()
|