From 46b322ff43c23f7a472c1c18628f152fe87a41f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Sun, 24 Nov 2024 01:57:38 +0100 Subject: [PATCH] new: Auto retry on HTTP requests --- pyvulnerabilitylookup/api.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyvulnerabilitylookup/api.py b/pyvulnerabilitylookup/api.py index 9a35b60..bd8ac19 100644 --- a/pyvulnerabilitylookup/api.py +++ b/pyvulnerabilitylookup/api.py @@ -13,6 +13,9 @@ from urllib.parse import urljoin, urlparse import requests +from urllib3.util import Retry +from requests.adapters import HTTPAdapter + def enable_full_debug() -> None: import http.client as http_client @@ -47,7 +50,8 @@ class PyVulnerabilityLookup(): self.session.headers['Content-Type'] = 'application/json' if proxies: self.session.proxies.update(proxies) - self.session.request = functools.partial(self.session.request, timeout=10) + retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504]) + self.session.mount('https://', HTTPAdapter(max_retries=retries)) def set_apikey(self, apikey: str) -> None: '''Set the API key to use for the requests'''