ChunkedEncodingError when reading data about ticker
I am trying to read tickers info using the following code:
tickers_list = ['NIO', 'PLTR', 'MSFT']
tickers = ' '.join(tickers_list)
tickers = yf.Tickers(tickers)
print(tickers.tickers['NIO'].info)
I get this error:
requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(82 bytes read, 1069 more expected)', IncompleteRead(82 bytes read, 1069 more expected))
Environment: python 3.6.1 MacOS BigSur
I'm getting the same when trying to download price history for stocks... I have been running these scripts several times daily for last years without much problem - but suddently they started to fail for well above 50% of the tickers I try to download since Thursday (1st of April). I'm running Python 3.8. I am experiencing these problems both in Windows and Linux environments... Would really appreciate if someone has any kind of input!
I also have this problem.
Have been trying various settings the last two days and I seem to get slightly more data with "threads"=False and I could probably live with the fact that you get some errors and that it is somewhat slow - but the primary problem right now is that the "ChunkedEncodingError" isn't returned until after almost 2 minutes...so it takes ages to run through a loop with try /except... Would be happy just to find a faster workaround at this stage, suggestions?
I've also been getting this error a lot since April 1st. I'm running Python 3.8.7 on macOS Big Sur.
Update: It seems to be a problem with Yahoo Finance. My browser gets stuck loading data sometimes as well when I go to https://query1.finance.yahoo.com.
My quick-fix workaround: Go to base.py in the yfinance library and add a timeout to the requests.get, that is, change
data = self.session.get(url=url, params=params, proxies=proxy)
to
data = self.session.get(url=url, params=params, proxies=proxy, timeout=0.1)
This way, you get a timeout error after 0.1 seconds instead of having to wait a couple of minutes for the connection broken error. You can then catch the timeout error like this
try:
data = yf.download(ticker, period="5d", interval="1m", threads = False, progress=False)
except requests.exceptions.RequestException:
pass
Note: You need to turn threads off otherwise you need to catch the error inside the threads.
Thanks! Will try that workaround while yahoofinance behaves like it does currently!
Latest version has timeout, can someone confirm problem gone.