Skip to content

Commit fd5384c

Browse files
authored
pass RESTClient a timeout in seconds (#41)
This will throw a `requests.ConnectTimeout` if the timeout is passed before the server responds. I believe the default amount of retries is 3, but I haven't checked.
1 parent caab917 commit fd5384c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

polygon/rest/client.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ class RESTClient:
1010
""" This is a custom generated class """
1111
DEFAULT_HOST = "api.polygon.io"
1212

13-
def __init__(self, auth_key: str):
13+
def __init__(self, auth_key: str, timeout: int=None):
1414
self.auth_key = auth_key
1515
self.url = "https://" + self.DEFAULT_HOST
1616

1717
self._session = requests.Session()
1818
self._session.params["apiKey"] = self.auth_key
19+
self.timeout = timeout
1920

2021
def __enter__(self):
2122
return self
@@ -27,7 +28,7 @@ def close(self):
2728
self._session.close()
2829

2930
def _handle_response(self, response_type: str, endpoint: str, params: Dict[str, str]) -> Type[models.AnyDefinition]:
30-
resp: requests.Response = self._session.get(endpoint, params=params)
31+
resp: requests.Response = self._session.get(endpoint, params=params, timeout=self.timeout)
3132
if resp.status_code == 200:
3233
return unmarshal.unmarshal_json(response_type, resp.json())
3334
else:

0 commit comments

Comments
 (0)