diff --git a/plaid/client.py b/plaid/client.py index 599b09806..a8829cc34 100644 --- a/plaid/client.py +++ b/plaid/client.py @@ -13,7 +13,7 @@ Sandbox, Transactions, ) -from plaid.requester import post_request +from plaid.requester import DEFAULT_TIMEOUT, post_request from plaid.utils import urljoin @@ -32,7 +32,8 @@ def __init__(self, secret, public_key, environment, - suppress_warnings=False): + suppress_warnings=False, + timeout=DEFAULT_TIMEOUT): ''' Initialize a client with credentials. @@ -42,12 +43,15 @@ def __init__(self, :arg str environment: One of ``sandbox``, ``development``, or ``production``. :arg bool suppress_warnings: Suppress Plaid warnings. + :arg int timeout: Timeout for API requests. + ''' self.client_id = client_id self.secret = secret self.public_key = public_key self.environment = environment self.suppress_warnings = suppress_warnings + self.timeout = timeout if self.environment == 'development' and not self.suppress_warnings: warnings.warn(''' @@ -94,4 +98,5 @@ def _post(self, path, data): return post_request( urljoin('https://' + self.environment + '.plaid.com', path), data=data, + timeout=self.timeout ) diff --git a/plaid/requester.py b/plaid/requester.py index 781b4cb92..ae63029c5 100644 --- a/plaid/requester.py +++ b/plaid/requester.py @@ -8,10 +8,10 @@ ALLOWED_METHODS = {'post'} -TIMEOUT = 600 # 10 minutes +DEFAULT_TIMEOUT = 600 # 10 minutes -def _requests_http_request(url, method, data): +def _requests_http_request(url, method, data, timeout=DEFAULT_TIMEOUT): normalized_method = method.lower() if normalized_method in ALLOWED_METHODS: return getattr(requests, normalized_method)( @@ -20,7 +20,7 @@ def _requests_http_request(url, method, data): headers={ 'User-Agent': 'Plaid Python v{}'.format(__version__), }, - timeout=TIMEOUT, + timeout=timeout, ) else: raise Exception( @@ -28,8 +28,8 @@ def _requests_http_request(url, method, data): ) -def http_request(url, method=None, data=None): - response = _requests_http_request(url, method, data or {}) +def http_request(url, method=None, data=None, timeout=DEFAULT_TIMEOUT): + response = _requests_http_request(url, method, data or {}, timeout) response_body = json.loads(response.text) if response_body.get('error_type'): raise PlaidError.from_response(response_body)