Skip to content

Commit c2f4000

Browse files
committed
Add default timeout
1 parent 58ef40c commit c2f4000

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/exchangerate/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ class ExchangerateClient:
88
Primary client class
99
@param api_key: the api key from https://apilayer.com/marketplace/fixer-api#documentation-tab
1010
"""
11-
def __init__(self, api_key: str):
11+
def __init__(self, api_key: str, timeout=None):
1212
self.api_key = api_key
13+
self.timeout = timeout or 10
1314
self.session = requests.Session()
1415

1516
# -------------------------------------------------------------------
@@ -43,7 +44,7 @@ def latest(self, base_currency="USD", symbols=None, amount=1):
4344
# -------------------------------------------------------------------
4445
def _validate_and_get_json(self, url):
4546
headers = {"apikey": self.api_key}
46-
resp = self.session.get(url, headers=headers)
47+
resp = self.session.get(url, headers=headers, timeout=self.timeout)
4748
if resp.status_code != 200:
4849
raise ResponseErrorException("Status code=%d calling url=%s" % (resp.status_code, url))
4950

0 commit comments

Comments
 (0)