Exemple #1
0
    def __init__(
            self,
            url,
            auth_key=None,
            timeout=60,
            max_retries=3,
            backoff_factor=0.05,
            backoff_max=10,
            status_forcelist=(500, 502, 503, 504),
    ):
        """Initialize.

        Args:
            url (str): URL to the NewReleases server.
            auth_key (str): NewReleases Auth key.
            timeout (int): Request timeout time.
            max_retries (int): Maximal number of retries.
            backoff_factor (float): Backoff factor.
            status_forcelist (tuple of int): Tuple of HTTP statuses for
                which the service should retry.
        """
        self.url = url
        self.auth_key = auth_key
        self.timeout = timeout
        self.max_retries = max_retries
        self.backoff_factor = backoff_factor
        self.backoff_max = backoff_max
        self.status_forcelist = status_forcelist

        # Setup headers
        self.headers = {"Content-Type": "application/json"}
        if self.auth_key is not None:
            self.headers["X-Key"] = self.auth_key

        self.response = None

        # setup connection pool
        self.session = Session()
        retry = Retry(
            total=max_retries,
            backoff_factor=backoff_factor,
            status_forcelist=status_forcelist,
        )
        retry.BACKOFF_MAX = backoff_max
        adapter = HTTPAdapter(max_retries=retry)
        self.session.mount(self.url, adapter)
Exemple #2
0
    def __init__(
        self,
        url,
        token="",
        timeout=60,
        max_retries=3,
        backoff_factor=0.05,
        backoff_max=10,
        status_forcelist=(500, 502, 503, 504),
    ):
        """Initialize.

        Args:
            url (str): URL to the SotaBench server.
            token (str): SotaBench authentication token.
            timeout (int): Request timeout time.
            max_retries (int): Maximal number of retries.
            backoff_factor (float): Backoff factor.
            status_forcelist (tuple of int): Tuple of HTTP statuses for
                which the service should retry.
        """
        self.url = url
        self.token = token
        self.timeout = timeout
        self.max_retries = max_retries
        self.backoff_factor = backoff_factor
        self.backoff_max = backoff_max
        self.status_forcelist = status_forcelist

        # Setup headers
        self.headers = {"Content-Type": "application/json"}
        if self.token.strip() != "":
            self.headers["Authorization"] = f"JWT {self.token}"

        self.response = None

        # setup connection pool
        self.session = Session()
        retry = Retry(
            total=max_retries,
            backoff_factor=backoff_factor,
            status_forcelist=status_forcelist,
        )
        retry.BACKOFF_MAX = backoff_max
        adapter = HTTPAdapter(max_retries=retry)
        self.session.mount(self.url, adapter)