File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments