'JSONDecodeError from Yahoo not catching

I am attempting to gather individual csv files on stocks using pandas_datareader and yfinance, both of which I'm using the most updated version of, however, I'm having a consistent issue with JSON and importing from Yahoo! Finance in this particular part of my code:

tickers = si.tickers_nasdaq()

for ticker in tickers:
    try:
        df = yf.download(ticker, start_date, end_date)
    except json.decoder.JSONDecodeError:
        print(f'JSON Decode Error on(ticker)')

    df.to_csv(f'{ticker}.csv')

and I after a seemingly random amount of successful downloads, I will still get the following error, it has not been consistent in which ticker the error appears on, or how much time has passed:

...
  

Exception in thread Thread-23:
Traceback (most recent call last):
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
    self.run()
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\site-packages\multitasking\__init__.py", line 102, in _run_via_pool
    return callee(*args, **kwargs)
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\site-packages\yfinance\multi.py", line 188, in _download_one_threaded
    data = _download_one(ticker, start, end, auto_adjust, back_adjust,
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\site-packages\yfinance\multi.py", line 202, in _download_one
    return Ticker(ticker).history(period=period, interval=interval,
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\site-packages\yfinance\base.py", line 194, in history
    data = data.json()
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 910, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\lakep\AppData\Local\Programs\Python\Python39\lib\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)

I'm looking for any information to help me overcome this roadblock, whether a solution to stop the error from appearing entirely or just some way the try-except to work properly?



Solution 1:[1]

There was a bug with yfinance before:

https://github.com/ranaroussi/yfinance/blob/main/.github/ISSUE_TEMPLATE/bug_report.md

try this:

 pip install yfinance --upgrade --no-cache-dir

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yilmaz