Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added timeout parameter to the constructor #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions articlemeta/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -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())
Expand Down Expand Up @@ -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
Expand Down