finnhub-python icon indicating copy to clipboard operation
finnhub-python copied to clipboard

Time out?

Open jasonpolstein opened this issue 4 years ago • 4 comments

New to Finnhub. I am running the following simple code and getting an error message. What is causing this?

CODE import finnhub import time import datetime import pandas as pd

Setup client finnhub_client = finnhub.Client(api_key="XXXXXXXXXXXXX")

Stock candles res = finnhub_client.stock_candles('AAPL', 'D', 1590988249, 1591852249) print(res)

ERROR MESSAGE Traceback (most recent call last): File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 426, in _make_request six.raise_from(e, None) File "", line 3, in raise_from File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 421, in _make_request httplib_response = conn.getresponse() File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/http/client.py", line 1332, in getresponse response.begin() File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/http/client.py", line 303, in begin version, status, reason = self._read_status() File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/http/client.py", line 264, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/socket.py", line 669, in readinto return self._sock.recv_into(b) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/ssl.py", line 1241, in recv_into return self.read(nbytes, buffer) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/ssl.py", line 1099, in read return self._sslobj.read(len, buffer) socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/adapters.py", line 439, in send resp = conn.urlopen( File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 724, in urlopen retries = retries.increment( File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/util/retry.py", line 403, in increment raise six.reraise(type(error), error, _stacktrace) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/packages/six.py", line 735, in reraise raise value File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen httplib_response = self._make_request( File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 428, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/urllib3/connectionpool.py", line 335, in _raise_timeout raise ReadTimeoutError( urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='finnhub.io', port=443): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "timeout-test.py", line 11, in res = finnhub_client.stock_candles('AAPL', 'D', 1590988249, 1591852249) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/finnhub/client.py", line 206, in stock_candles return self._get("/stock/candle", params=params) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/finnhub/client.py", line 69, in _get return self._request("get", path, **kwargs) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/finnhub/client.py", line 38, in _request response = getattr(self._session, method)(uri, **kwargs) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py", line 543, in get return self.request('GET', url, **kwargs) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py", line 530, in request resp = self.send(prep, **send_kwargs) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/sessions.py", line 643, in send r = adapter.send(request, **kwargs) File "/Users/jasonpolstein/opt/anaconda3/lib/python3.8/site-packages/requests/adapters.py", line 529, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='finnhub.io', port=443): Read timed out. (read timeout=10)

jasonpolstein avatar Feb 18 '21 15:02 jasonpolstein

I have same issue, finnhub_client.aggregate_indicator fails half of the time

dejoski avatar Apr 20 '21 15:04 dejoski

I have the same issue with pattern_recognition. Is there no way to increase the timeout value?

enoch-prince avatar Aug 14 '21 11:08 enoch-prince

@enoch-prince , @jasonpolstein , @dejoski Just ran into the same issues. If you go into the Client class file (called client.py, in VSCode you can hold control and click on the Client class declaration wherever it is in your code to move to where that class is defined), change the DEFAULT_TIMEOUT value. Increased mine to 120 seconds. So far no issues.

EDIT: So now instead of a read timeout, I'm running into a 504: Gateway time-out from the API. Seems that Finnhub may not be able to keep up with API requests.... I've reached out to their support to identify the issues and see if they are working on something like scaling solutions.

Great service in theory but I may be moving onto different API until Finnhub can resolve these issues.

KosherMeatBoy avatar Nov 17 '21 19:11 KosherMeatBoy

I am still having the issues mentioned above. Has there been no fix for this?

ghost avatar Nov 23 '23 18:11 ghost