From f52f506be428fe84c6ffdd97c00b547a0b940ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 26 Nov 2024 01:42:39 +0100 Subject: [PATCH] chg: Add retry --- pylacus/api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pylacus/api.py b/pylacus/api.py index 101b949..f0f55c1 100644 --- a/pylacus/api.py +++ b/pylacus/api.py @@ -12,6 +12,9 @@ import requests +from urllib3.util import Retry +from requests.adapters import HTTPAdapter + BROWSER = Literal['chromium', 'firefox', 'webkit'] @@ -112,6 +115,8 @@ def __init__(self, root_url: str, useragent: str | None=None, self.session.headers['user-agent'] = useragent if useragent else f'PyLacus / {version("pylacus")}' if proxies: self.session.proxies.update(proxies) + retries = Retry(total=5, backoff_factor=0.1, status_forcelist=[500, 502, 503, 504]) + self.session.mount('http://', HTTPAdapter(max_retries=retries)) @property def is_up(self) -> bool: