Skip to content

Commit 5fe3218

Browse files
committed
Add request options.
1 parent 2b8690d commit 5fe3218

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

ipinfo/handler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ class Handler:
2222
CACHE_MAXSIZE = 4096
2323
CACHE_TTL = 60 * 60 * 24
2424
COUNTRY_FILE_DEFAULT = 'countries.json'
25+
REQUEST_TIMEOUT_DEFAULT = 2
2526

2627
def __init__(self, access_token=None, **kwargs):
2728
"""Initialize the Handler object with country name list and the cache initialized."""
2829
self.access_token = access_token
2930
self.countries = self._read_country_names(kwargs.get('countries_file'))
3031

32+
self.request_options = kwargs.get('request_options', {})
33+
if 'timeout' not in self.request_options:
34+
self.request_options['timeout'] = self.REQUEST_TIMEOUT_DEFAULT
35+
3136
if 'cache' in kwargs:
3237
self.cache = kwargs['cache']
3338
else:
@@ -57,7 +62,7 @@ def _requestDetails(self, ip_address=None):
5762
if ip_address:
5863
url += '/' + ip_address
5964

60-
response = requests.get(url, headers=self._get_headers())
65+
response = requests.get(url, headers=self._get_headers(), **self.request_options)
6166
if response.status_code == 429:
6267
raise RequestQuotaExceededError()
6368
response.raise_for_status()

0 commit comments

Comments
 (0)