Here are the examples of the python api requests.packages.urllib3.util.retry.Retry taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
136 Examples
3
Source : osm.py
with MIT License
from adaj
with MIT License
from adaj
def requests_retry_session(retries=3, backoff_factor=0.5, session=None,
status_forcelist=(500, 503, 502, 504)):
session = session or Session()
retry = Retry(total=retries, read=retries, connect=retries,
backoff_factor=backoff_factor, status_forcelist=status_forcelist)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def overpass_result_to_geodf(result, as_points=False):
3
Source : test_prometheus_connect.py
with MIT License
from AICoE
with MIT License
from AICoE
def test_retry_on_error(self): # noqa D102
retry = Retry(total=3, backoff_factor=0.1, status_forcelist=[400])
pc = PrometheusConnect(url=self.prometheus_host, disable_ssl=True, retry=retry)
with self.assertRaises(requests.exceptions.RetryError, msg="too many 400 error responses"):
pc.custom_query("BOOM.BOOM!#$%")
class TestPrometheusConnectWithMockedNetwork(BaseMockedNetworkTestcase):
3
Source : stashapi.py
with MIT License
from ajs
with MIT License
from ajs
def requests_context():
session = requests.Session()
retry = urllib_retry.Retry(
total=10,
backoff_factor=1,
status_forcelist=(500, 502, 503, 504))
adapter = requests_adapters.HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
# Our abstract base creates its public methods dynamically
# pylint: disable=too-few-public-methods
class PoeApiData:
3
Source : utils.py
with MIT License
from akornor
with MIT License
from akornor
def requests_retry_session(
retries=3, backoff_factor=1, status_forcelist=(429, 500, 502, 503, 504), session=None
):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
method_whitelist=["HEAD", "GET", "PUT", "DELETE", "OPTIONS", "TRACE"]
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session
def get_spotify_client():
3
Source : http.py
with Apache License 2.0
from allenai
with Apache License 2.0
from allenai
def session_with_backoff() -> requests.Session:
"""
We ran into an issue where http requests to s3 were timing out,
possibly because we were making too many requests too quickly.
This helper function returns a requests session that has retry-with-backoff
built in. See
< https://stackoverflow.com/questions/23267409/how-to-implement-retry-mechanism-into-python-requests-library>.
"""
session = requests.Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=RECOVERABLE_SERVER_ERROR_CODES)
session.mount("http://", HTTPAdapter(max_retries=retries))
session.mount("https://", HTTPAdapter(max_retries=retries))
return session
class HttpClient(SchemeClient):
3
Source : file_utils.py
with MIT License
from alontalmor
with MIT License
from alontalmor
def session_with_backoff() -> requests.Session:
"""
We ran into an issue where http requests to s3 were timing out,
possibly because we were making too many requests too quickly.
This helper function returns a requests session that has retry-with-backoff
built in.
see stackoverflow.com/questions/23267409/how-to-implement-retry-mechanism-into-python-requests-library
"""
session = requests.Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504])
session.mount('http://', HTTPAdapter(max_retries=retries))
session.mount('https://', HTTPAdapter(max_retries=retries))
return session
def http_get(url: str, temp_file: IO) -> None:
3
Source : gebieden.py
with Mozilla Public License 2.0
from Amsterdam
with Mozilla Public License 2.0
from Amsterdam
def _get_session(self):
"""Create a requests HTTP session with retries."""
session = requests.session()
session.mount('https', HTTPAdapter(
max_retries=Retry(
total=5,
backoff_factor=1,
status_forcelist=[502, 503, 504]
)
))
return session
def _iterate_urls(self, requests_session, url):
3
Source : open_data_service.py
with GNU General Public License v3.0
from bdhowald
with GNU General Public License v3.0
from bdhowald
def __init__(self):
# Set up retry ability
s_req = requests_futures.sessions.FuturesSession(max_workers=9)
retries = Retry(total=5,
backoff_factor=0.1,
status_forcelist=[403, 500, 502, 503, 504],
raise_on_status=False)
s_req.mount('https://', HTTPAdapter(max_retries=retries))
self.api = s_req
self.location_service = LocationService()
def lookup_covid_19_camera_violations(self) -> list[dict[str, str]]:
3
Source : tweet_detection_service.py
with GNU General Public License v3.0
from bdhowald
with GNU General Public License v3.0
from bdhowald
def __init__(self):
# Set up retry ability
s_req = requests_futures.sessions.FuturesSession(max_workers=5)
retries = Retry(total=5,
backoff_factor=0.1,
status_forcelist=[403, 500, 502, 503, 504],
raise_on_status=False)
s_req.mount('https://', HTTPAdapter(max_retries=retries))
self.api = s_req
def tweet_exists(self, id: int, username: str) -> bool:
3
Source : bitbns.py
with MIT License
from bitbns-official
with MIT License
from bitbns-official
def __init__(self, apiKey, apiSecretKey, timeout = 30):
self.__setTimeout(timeout)
self.apiKeys['apiKey'] = apiKey
self.apiKeys['apiSecretKey'] = apiSecretKey
self.connectionsAdaptor = requests.Session()
self.connectionsAdaptor.mount('https://', HTTPAdapter(max_retries = Retry(total = 3)))
headers = {'X-BITBNS-APIKEY': apiKey}
response = self.connectionsAdaptor.get('https://api.bitbns.com/api/trade/v1/getServerTime', headers=headers)
response = response.json()
serverTime = int(response['serverTime'])
localTime = int(time.time() * 1000.0)
self.timeOffset = localTime - serverTime
@classmethod
3
Source : bitbns.py
with MIT License
from bitbns-official
with MIT License
from bitbns-official
def publicEndpoints(cls, timeout = 30):
obj = cls.__new__(cls)
super(bitbns, obj).__init__()
obj.__setTimeout(timeout)
obj.apiKeys['apiKey'] = ''
obj.apiKeys['apiSecretKey'] = ''
obj.connectionsAdaptor = requests.Session()
obj.connectionsAdaptor.mount('https://', HTTPAdapter(max_retries = Retry(total = 3)))
return obj
def __setTimeout(self, timeout):
3
Source : retina_net.py
with GNU General Public License v3.0
from CCExtractor
with GNU General Public License v3.0
from CCExtractor
def retry_request(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
logger.info(msg="retry_request called")
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
class FaceDetectionRetina(object):
3
Source : vsmart_switch.py
with Apache License 2.0
from CloudNativeSDWAN
with Apache License 2.0
from CloudNativeSDWAN
def get_request(self, mount_point):
"""GET request"""
url = "https://%s:8443/dataservice/%s"%(self.vmanage_ip, mount_point)
print("GET ", url)
retries = Retry(total=7, backoff_factor=1, status_forcelist=[400, 404])
self.session[self.vmanage_ip].mount('https://', HTTPAdapter(max_retries=retries))
response = self.session[self.vmanage_ip].get(url, verify=False)
print("Status Code: ", response.status_code)
print('Response: ', response)
return response
def post_request(self, mount_point, payload, headers={'Content-Type': 'application/json'}):
3
Source : requests_retry.py
with Apache License 2.0
from Code4PuertoRico
with Apache License 2.0
from Code4PuertoRico
def requests_retry_session(
retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None
):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session
3
Source : client.py
with GNU Affero General Public License v3.0
from cogsec-collaborative
with GNU Affero General Public License v3.0
from cogsec-collaborative
def client():
# Handles rate limit by reading 429 status code in HTTP header.
retry_strategy = Retry(
total=7,
# Use incremental backoff.
backoff_factor=1,
status_forcelist=[429, 500, 502, 503, 504],
method_whitelist=["GET", "PATCH"]
)
adapter = TimeoutHTTPAdapter(timeout=2, max_retries=retry_strategy)
session = requests.Session()
session.headers["User-Agent"] = "Parler%20Staging/545 CFNetwork/978.0.7 Darwin 18.7.0"
session.mount("https://", adapter)
session.mount("http://", adapter)
return session
3
Source : utils.py
with GNU General Public License v3.0
from containerbuildsystem
with GNU General Public License v3.0
from containerbuildsystem
def get_requests_session():
"""
Get a request session with a retry option.
:return: the requests session
:rtype: requests.Session
"""
session = requests.Session()
retry = Retry(
total=5, read=5, connect=5, backoff_factor=1.3, status_forcelist=(500, 502, 503, 504)
)
adapter = requests.adapters.HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session
def get_sha256_hash_from_file(filename):
3
Source : allennlp_file_utils.py
with MIT License
from ConvLab
with MIT License
from ConvLab
def session_with_backoff() -> requests.Session:
"""
We ran into an issue where http requests to s3 were timing out,
possibly because we were making too many requests too quickly.
This helper function returns a requests session that has retry-with-backoff
built in.
see https://stackoverflow.com/questions/23267409/how-to-implement-retry-mechanism-into-python-requests-library
"""
session = requests.Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504])
session.mount('http://', HTTPAdapter(max_retries=retries))
session.mount('https://', HTTPAdapter(max_retries=retries))
return session
def http_get(url: str, temp_file: IO) -> None:
3
Source : get.py
with MIT License
from cradlepoint
with MIT License
from cradlepoint
def establish_session():
with requests.Session() as session:
retries = Retry(total=5, # Total number of retries to allow.
backoff_factor=2,
status_forcelist=[408, # 408 Request Timeout
500, # 500 Internal Server Error
502, # 502 Bad Gateway
503, # 503 Service Unavailable
504, # 504 Gateway Timeout
],
)
a = HTTPAdapter(max_retries=retries)
session.mount('https://', a)
return session
def next_url(self):
3
Source : crypto_history.py
with MIT License
from dc-aichara
with MIT License
from dc-aichara
def __init__(self,
base_url: Optional[str] = __Crypto_Market_Base_URL) -> None:
self.base_url = base_url
self.request_timeout = 120
self.session = requests.Session()
retries = Retry(
total=5, backoff_factor=0.5, status_forcelist=[502, 503, 504]
)
self.session.mount("http://", HTTPAdapter(max_retries=retries))
def __request(self, url: str) -> pd.DataFrame:
3
Source : bulk_download.py
with Apache License 2.0
from EBI-Metagenomics
with Apache License 2.0
from EBI-Metagenomics
def __init__(self, project_id, output_path, version, result_group):
self.project_id = project_id
self.output_path = output_path
self.version = version
self.result_group = result_group
self._init_program()
self.headers = {
"Accept": "application/vnd.api+json",
}
# http session
retry_strategy = Retry(
total=3, status_forcelist=[500, 502, 503, 504], backoff_factor=1
)
retry_adapter = HTTPAdapter(max_retries=retry_strategy)
http = Session()
http.mount(MG_ANALYSES_BASE_URL, retry_adapter)
self.http = http
def _init_program(self):
3
Source : coingecko.py
with MIT License
from economicnetwork
with MIT License
from economicnetwork
def __init__(self, api_base_url = __API_URL_BASE):
self.api_base_url = api_base_url
self.request_timeout = 120
self.session = requests.Session()
retries = Retry(total=5, backoff_factor=0.5, status_forcelist=[ 502, 503, 504 ])
self.session.mount('http://', HTTPAdapter(max_retries=retries))
def __request(self, url):
3
Source : catalog.py
with MIT License
from geosolutions-it
with MIT License
from geosolutions-it
def setup_connection(self, retries=3, backoff_factor=0.9):
self.client = requests.session()
self.client.verify = self.validate_ssl_certificate
parsed_url = urlparse(self.service_url)
retry = Retry(
total = retries or self.retries,
status = retries or self.retries,
read = retries or self.retries,
connect = retries or self.retries,
backoff_factor = backoff_factor or self.backoff_factor,
status_forcelist = [502, 503, 504],
method_whitelist = set(['HEAD', 'TRACE', 'GET', 'PUT', 'POST', 'OPTIONS', 'DELETE'])
)
self.client.mount("{}://".format(parsed_url.scheme), HTTPAdapter(max_retries=retry))
def http_request(self, url, data=None, method='get', headers={}):
3
Source : http.py
with GNU General Public License v3.0
from Hari-Nagarajan
with GNU General Public License v3.0
from Hari-Nagarajan
def __init__(self, *args, **kwargs):
self.timeout = kwargs.get("timeout", DEFAULT_TIMEOUT)
super().__init__(
max_retries=kwargs.get(
"max_retries",
Retry(
total=10,
backoff_factor=1,
status_forcelist=[429, 500, 502, 503, 504],
method_whitelist=["HEAD", "GET", "OPTIONS"],
),
)
)
def send(self, request, **kwargs):
3
Source : common.py
with Apache License 2.0
from jay0lee
with Apache License 2.0
from jay0lee
def build_http():
retry_strategy = Retry(
total=10,
status_forcelist=[429, 500, 502, 503, 504],
method_whitelist=["HEAD", "GET", "OPTIONS"]
)
adapter = HTTPAdapter(max_retries=retry_strategy)
httpc = requests.Session()
httpc.mount("https://", adapter)
httpc.mount("http://", adapter)
return httpc
def check_updates(appid, version, board, track, hardware_class, targetversionprefix='', installsource='ondemand'):
3
Source : google_translator.py
with MIT License
from johnbumgarner
with MIT License
from johnbumgarner
def _requests_retry_session(retries=5,
backoff_factor=0.5,
status_forcelist=(500, 502, 504),
session=None,
):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def _google_translate(self, original_language):
3
Source : mymemory_translator.py
with MIT License
from johnbumgarner
with MIT License
from johnbumgarner
def _requests_retry_session(retries=5,
backoff_factor=0.5,
status_forcelist=(500, 502, 504),
session=None,
):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def _mymemory_translate(self, original_language):
3
Source : mangadex_org.py
with GNU General Public License v3.0
from Kanjirito
with GNU General Public License v3.0
from Kanjirito
def __init__(self, limit=6, backoff_factor=1, status_forcelist=None, **kwargs):
if status_forcelist is None:
status_forcelist = [429]
r = Retry(
status=limit,
total=None,
connect=0,
read=0,
redirect=0,
other=0,
status_forcelist=status_forcelist,
backoff_factor=backoff_factor,
respect_retry_after_header=False,
)
super().__init__(max_retries=r, **kwargs)
class ReporterLimiter(Limiter):
3
Source : locust.py
with MIT License
from ktanakaj
with MIT License
from ktanakaj
def __init__(self, *args, **kwargs):
super(AppLocust, self).__init__(*args, **kwargs)
# 環境別の設定ファイルを取得
self.config = config.get(self.host)
# クライアントにデフォルトの設定を追加、リトライも指定
self.client.headers['User-Agent'] = self.config.USER_AGENT
self.client.headers['Accept'] = "application/json, text/html, text/plain"
retries = Retry(total=self.config.MAX_RETRY,
backoff_factor=1, status_forcelist=[500, 502, 503, 504])
self.client.mount('https://', HTTPAdapter(max_retries=retries))
self.client.mount('http://', HTTPAdapter(max_retries=retries))
self.client.verify = False
3
Source : retry.py
with GNU General Public License v3.0
from LayerManager
with GNU General Public License v3.0
from LayerManager
def get_session(*, retries=5):
session = requests.Session()
retry = Retry(
total=retries,
backoff_factor=0.2, # Used to compute time in seconds between attempts:
# backoff_factor * (2 ** attempt_idx - 1))
# if backoff_factor=0.2, it waits for [0.1, 0.2, 0.4, 0.8, ...]
status_forcelist=(500,),
method_whitelist=('HEAD', 'TRACE', 'GET', 'PUT', 'OPTIONS', 'DELETE', 'POST', 'PATCH')
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
3
Source : myrequests.py
with The Unlicense
from lbp0200
with The Unlicense
from lbp0200
def requests_retry_session(retries=3,
backoff_factor=0.3,
status_forcelist=(500, 502, 504),
session=None,
):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
3
Source : helpers.py
with GNU General Public License v3.0
from m-kus
with GNU General Public License v3.0
from m-kus
def requests_retry_session(retries=3, backoff_factor=0.3, status_forcelist=(500, 502, 504), session=None):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def make_flask_response(response):
3
Source : api.py
with MIT License
from man-c
with MIT License
from man-c
def __init__(self, api_base_url=__API_URL_BASE):
self.api_base_url = api_base_url
self.request_timeout = 120
self.session = requests.Session()
retries = Retry(total=5, backoff_factor=0.5, status_forcelist=[502, 503, 504])
self.session.mount('http://', HTTPAdapter(max_retries=retries))
def __request(self, url):
3
Source : api_calls.py
with Apache License 2.0
from mapswipe
with Apache License 2.0
from mapswipe
def retry_get(url, retries=3, timeout=4, to_osmcha: bool = False):
"""Retry a query for a variable amount of tries."""
retry = Retry(total=retries)
with requests.Session() as session:
session.mount("https://", HTTPAdapter(max_retries=retry))
if to_osmcha:
headers = {"Authorization": f"Token {OSMCHA_API_KEY}"}
return session.get(url, timeout=timeout, headers=headers)
else:
return session.get(url, timeout=timeout)
def geojsonToFeatureCollection(geojson: dict) -> dict:
3
Source : conda_channel.py
with MIT License
from MetroStar
with MIT License
from MetroStar
def improved_download(url):
session = requests.Session()
retry = Retry(connect=5, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session.get(url)
class CondaChannel:
3
Source : crawler.py
with GNU General Public License v3.0
from mfdz
with GNU General Public License v3.0
from mfdz
def __init__(self, config_file = 'config.ini', config_section = 'default'):
self._config = config = configparser.ConfigParser()
self._config.read(config_file)
self._config_section = config_section
self._session = requests.Session()
retries = Retry(total=10,
backoff_factor=0.1,
status_forcelist=[ 500, 502, 503, 504 ])
self._session.mount('http://', HTTPAdapter(max_retries=retries))
@property
3
Source : utils.py
with MIT License
from microsoft
with MIT License
from microsoft
def retry_session(retries: int = 3) -> requests.Session:
"""Create a requests.Session with retries."""
session = requests.Session()
retry = Retry(total=retries)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session
def get_url(
3
Source : FB_Bot.py
with GNU Lesser General Public License v3.0
from MorenK1
with GNU Lesser General Public License v3.0
from MorenK1
def create_session():
session = requests.Session()
retry = Retry(total=10, connect=3, redirect=5, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def get_url(url): # get webpages as general files
3
Source : utils.py
with Mozilla Public License 2.0
from mozilla
with Mozilla Public License 2.0
from mozilla
def get_session(name: str) -> requests.Session:
session = requests.Session()
retry = Retry(total=9, backoff_factor=1, status_forcelist=[429, 500, 502, 503, 504])
# Default HTTPAdapter uses 10 connections. Mount custom adapter to increase
# that limit. Connections are established as needed, so using a large value
# should not negatively impact performance.
http_adapter = requests.adapters.HTTPAdapter(
pool_connections=50, pool_maxsize=50, max_retries=retry
)
session.mount("https://", http_adapter)
session.mount("http://", http_adapter)
return session
def get_hgmo_stack(branch: str, revision: str) -> list[bytes]:
3
Source : conftest.py
with Mozilla Public License 2.0
from mozilla
with Mozilla Public License 2.0
from mozilla
def _verify_url(request, server_url: str, user: User, org: str) -> None:
"""Verifies the base URL.
This will ping the base url until it returns a 200.
"""
if server_url and request.config.option.verify_server_url:
session = Session()
retries = Retry(backoff_factor=0.1, status_forcelist=[500, 502, 503, 504])
session.mount(server_url, HTTPAdapter(max_retries=retries))
session.get(server_url, verify=False)
@pytest.fixture(name="server_url", scope="session")
3
Source : abstract_client.py
with MIT License
from ParticleDev
with MIT License
from ParticleDev
def _get_session(self) -> requests.Session:
"""
Initialize and return a session allows make retry when some errors
will raised.
"""
session = requests.Session()
retry = rq_retry.Retry(
total=self.retries_number,
read=self.retries_number,
connect=self.retries_number,
backoff_factor=self.backoff_factor,
status_forcelist=self.status_forcelist,
)
adapter = rq_adapt.HTTPAdapter(max_retries=retry)
session.mount("https://", adapter)
return session
def _make_request(self, *args: Any, **kwargs: Any) -> requests.Response:
3
Source : file_utils.py
with Apache License 2.0
from PYART0
with Apache License 2.0
from PYART0
def _session_with_backoff() -> requests.Session:
"""
We ran into an issue where http requests to s3 were timing out,
possibly because we were making too many requests too quickly.
This helper function returns a requests session that has retry-with-backoff
built in. See
< https://stackoverflow.com/questions/23267409/how-to-implement-retry-mechanism-into-python-requests-library>.
"""
session = requests.Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=[502, 503, 504])
session.mount("http://", HTTPAdapter(max_retries=retries))
session.mount("https://", HTTPAdapter(max_retries=retries))
return session
def _http_etag(url: str) -> Optional[str]:
3
Source : utils.py
with GNU General Public License v3.0
from sachaw
with GNU General Public License v3.0
from sachaw
def requests_retry_session(
retries=3,
backoff_factor=0.3,
status_forcelist=(500, 502, 504),
session=None,
):
session = session or requests.Session()
retry = Retry(
total=retries,
read=retries,
connect=retries,
backoff_factor=backoff_factor,
status_forcelist=status_forcelist,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
3
Source : core.py
with MIT License
from sampsyo
with MIT License
from sampsyo
def retry_session():
"""Get a Requests session that retries HTTP and HTTPS requests."""
# Adapted from:
# https://www.peterbe.com/plog/best-practice-with-retries-with-requests
session = requests.Session()
retry = Retry(
total=RETRY_COUNT,
read=RETRY_COUNT,
connect=RETRY_COUNT,
backoff_factor=RETRY_FACTOR,
status_forcelist=RETRY_STATUSES,
)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
return session
def set_log_level(level: int):
3
Source : splunk_http_event_collector.py
with MIT License
from splunk
with MIT License
from splunk
def requests_retry_session(self, retries=3,backoff_factor=0.3,status_forcelist=(408,500,502,503,504),session=None):
session = session or requests.Session()
retry = Retry(total=retries, read=retries, connect=retries, backoff_factor=backoff_factor, status_forcelist=status_forcelist, method_whitelist=frozenset(['HEAD', 'TRACE', 'GET', 'PUT', 'OPTIONS', 'DELETE', 'POST']))
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def __init__(self,token,http_event_server,input_type='json',host="",http_event_port='8088',http_event_server_ssl=True):
3
Source : helpers.py
with MIT License
from sspbft
with MIT License
from sspbft
def session():
"""Sets up a HTTP session with a retry policy."""
s = requests.Session()
retries = Retry(total=5, backoff_factor=0.5)
s.mount("http://", HTTPAdapter(max_retries=retries))
return s
async def GET(node_id, path):
3
Source : client.py
with MIT License
from strombergdev
with MIT License
from strombergdev
def __init__(self, token, host='https://api.frame.io'):
self.token = token
self.host = host
self.retry_strategy = Retry(
total=3,
backoff_factor=1,
status_forcelist=[429],
method_whitelist=["POST", "OPTIONS", "GET"]
)
self.client_version = '3.6.8'
def _get_version(self):
3
Source : download.py
with MIT License
from strombergdev
with MIT License
from strombergdev
def __init__(self, asset, download_folder, replace):
self.asset = asset
self.download_folder = download_folder
self.replace = replace
self.attempts = 0
self.retry_limit = 3
self.http_retry_strategy = Retry(
total=3,
backoff_factor=1,
status_forcelist=[408, 500, 502, 503, 504],
method_whitelist=['GET']
)
def download(self):
3
Source : tezos_rpc_client.py
with MIT License
from tezzigator
with MIT License
from tezzigator
def send_request(self, uri):
url = '{}/{}'.format(self.node_url, uri)
logging.info('Performing get request {}'.format(url))
response = None
with requests.Session() as s:
retries = Retry(
total=self.RETRIES,
backoff_factor=0.2,
status_forcelist=[500, 502, 503, 504])
s.mount('http://', HTTPAdapter(max_retries=retries))
s.mount('https://', HTTPAdapter(max_retries=retries))
response = s.get(url, timeout=self.TIMEOUT)
logging.info('Got response {}'.format(response))
return response
def get_current_block(self):
3
Source : binance_futures_api.py
with MIT License
from TheFourGreatErrors
with MIT License
from TheFourGreatErrors
def _init_session(self):
session = requests.session()
session.headers.update({'Accept': 'application/json',
'User-Agent': 'binance/python',
'X-MBX-APIKEY': self.API_KEY})
retry = Retry(total=10,
backoff_factor=1,
status_forcelist=[ 500, 502, 503, 504 ])
adapter = HTTPAdapter(max_retries=retry)
session.mount('http://', adapter)
session.mount('https://', adapter)
return session
def _create_api_uri(self, path, signed=True, version=PUBLIC_API_VERSION):
3
Source : rest_helpers.py
with BSD 3-Clause "New" or "Revised" License
from theislab
with BSD 3-Clause "New" or "Revised" License
from theislab
def rest_api_collection_request(url):
retry_strategy = Retry(
backoff_factor=0,
method_whitelist=["GET"],
status_forcelist=HTTP_ERROR_LIST,
total=MAX_RETRIES,
)
adapter = CustomHTTPAdapter(timeout=TIMEOUT_COLLECTION, max_retries=retry_strategy)
https = requests.Session()
https.mount("https://", adapter)
r = https.get(url)
r.raise_for_status()
return r.json()
def rest_api_data_request(presigned_url):
See More Examples