From a438ae49b5a3957656e5245eebabcbf6240eef6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Augusto=20Salim?= Date: Wed, 13 Oct 2021 15:20:09 -0300 Subject: [PATCH] Added timeout to the constructor --- articlemeta/client.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/articlemeta/client.py b/articlemeta/client.py index 77e2292..d951f2b 100644 --- a/articlemeta/client.py +++ b/articlemeta/client.py @@ -83,13 +83,16 @@ class RestfulClient(object): ISSUES_ENDPOINT = '/api/v1/issues' COLLECTION_ENDPOINT = '/api/v1/collection' ATTEMPTS = 10 + + _timeout = 3 - def __init__(self, domain=None): + def __init__(self, domain=None, timeout=3): if domain: self.ARTICLEMETA_URL = domain + self._timeout = timeout - def _do_request(self, url, params=None, timeout=3, method='GET'): + def _do_request(self, url, params=None, method='GET'): request = requests.get params = params if params else {} @@ -105,7 +108,7 @@ def _do_request(self, url, params=None, timeout=3, method='GET'): # So, to not receive a "too many connections error (249 HTTP ERROR)", do not change this line. time.sleep(0.4) try: - result = request(url, params=params, timeout=timeout) + result = request(url, params=params, timeout=self._timeout) if result.status_code == 401: logger.error('Unautorized Access for (%s)', url) logger.exception(UnauthorizedAccess()) @@ -465,7 +468,7 @@ def documents( while True: url = urljoin(self.ARTICLEMETA_URL, self.ARTICLES_ENDPOINT) - articles = self._do_request(url, params=params, timeout=10) + articles = self._do_request(url, params=params) if articles is None: break