yfinance: Getting json.decoder.JSONDecodeError: Expecting value
Getting this error randomly and the thread is stuck. Tried upgrading the library but doesn’t work.
Here’s the trace:
Traceback (most recent call last):
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.9/site-packages/multitasking/__init__.py", line 102, in _run_via_pool
return callee(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/yfinance/multi.py", line 169, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "/usr/local/lib/python3.9/site-packages/yfinance/multi.py", line 181, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "/usr/local/lib/python3.9/site-packages/yfinance/base.py", line 162, in history
data = data.json()
File "/usr/local/lib/python3.9/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/python@3.9/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)```
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 32 (2 by maintainers)
same issue here on version == 0.1.60, however resolved
pip install yfinance==0.1.62
in my case.@ranaroussi From what I’ve seen this error isn’t thrown from the library. I can see the error in the logs but the thread that called the download function hangs. Any external logic I can implement here is irrelevant due to that.
Adding ‘threads=False’ seems to have mitigated to issue for me. Not sure if it’s a permanent solution yet.
Same issue here. I’ve been using the same script for the past few weeks with no issues. Bulk downloading chunks of 100 tickers for appx 2500-4000 tickers. Just started getting this error this week. Something has changed on Yahoo’s end.
I can’t reproduce this with 0.1.63… 🤷♂️
Successfully downloaded all nasdaq tickers data this AM in chunks of 100 with
threads = False
. Execution time went from .3 secs per stock to .9 secs, but it worked.@Ozymandias1700 i concur. i did see different behavior on different machines with different compute power. I think this has something to do with how fast the threads (default) are generated or frequency of requests that are sent to yahoo servers. Let me try with
threads=False
, will report back.The only solution that worked for me over 2 days.
@CKDarling
yf.__version__ Out[176]: '0.1.63'
Yes are right, if you run it with a couple of symbols and define start and end date it does work. However I tried to run this for 8800 symbols:
yf.download(" ".join(symbols),start="2020-01-01",end="2021-01-01").head()
And this is what happens:
@CKDarling try runing that code for a large number of tickers.
Is it possible for the library to report errors or break execution so that we can try-catch it. That way we can enforce a delay between the ticker downloads. Maybe this already exists.
@ranaroussi it doesn’t happen for all tickers, only some. I attempted to download ~11,000 tickers data and got this error many times. It also hangs at the end of the downloads sometimes but that’s a separate issue.