Skip to content

Commit

Permalink
new: Auto retry on HTTP requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Nov 24, 2024
1 parent bd1684e commit 46b322f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pyvulnerabilitylookup/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

import requests

from urllib3.util import Retry
from requests.adapters import HTTPAdapter


def enable_full_debug() -> None:
import http.client as http_client
Expand Down Expand Up @@ -47,7 +50,8 @@ def __init__(self, root_url: str='https://vulnerability.circl.lu', useragent: st
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'''
Expand Down

0 comments on commit 46b322f

Please sign in to comment.