yfinance: JSONDecodeError with 0.2.54

Mod edit: only reply if yf.__version__ prints latest version. Ignore PIP Conda etc


Describe bug

I keep getting "[100%**] 1 of 1 completed

1 Failed download: [‘AAPL’]: JSONDecodeError(‘Expecting value: line 1 column 1 (char 0)’)" This only happened 2 days ago. Upgrading yfinance to 0.2.54 did not help.

Simple code that reproduces your problem

import yfinance as yf dat = yf.download(‘AAPL’, period=‘1mo’) print(dat)

Debug log

DEBUG Entering download() DEBUG Disabling multithreading because DEBUG logging enabled DEBUG Entering history() DEBUG Entering history() DEBUG AAPL: Yahoo GET parameters: {‘range’: ‘1mo’, ‘interval’: ‘1d’, ‘includePrePost’: False, ‘events’: ‘div,splits,capitalGains’} DEBUG Entering get() DEBUG url=https://query2.finance.yahoo.com/v8/finance/chart/AAPL DEBUG params={‘range’: ‘1mo’, ‘interval’: ‘1d’, ‘includePrePost’: False, ‘events’: ‘div,splits,capitalGains’} DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = ‘basic’ DEBUG Entering _get_cookie_and_crumb_basic() DEBUG reusing cookie DEBUG reusing crumb DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting _get_cookie_and_crumb() DEBUG response code=429 DEBUG toggling cookie strategy basic -> csrf DEBUG Entering _get_cookie_and_crumb() DEBUG cookie_mode = ‘csrf’ DEBUG Entering _get_crumb_csrf() DEBUG Failed to find “csrfToken” in response DEBUG Exiting _get_crumb_csrf() DEBUG toggling cookie strategy csrf -> basic DEBUG Entering _get_cookie_and_crumb_basic() DEBUG loaded persistent cookie DEBUG reusing cookie DEBUG crumb = ‘Edge: Too Many Requests’ DEBUG Exiting _get_cookie_and_crumb_basic() DEBUG Exiting get_cookie_and_crumb() DEBUG response code=429 DEBUG Exiting get() ERROR
1 Failed download: ERROR [‘AAPL’]: JSONDecodeError(‘Expecting value: line 1 column 1 (char 0)’) DEBUG [‘AAPL’]: Traceback (most recent call last): File “C:\Users\Admin\anaconda3\envs\new_env1\lib\site-packages\requests\models.py”, line 974, in json return complexjson.loads(self.text, **kwargs) File "C:\Users\Admin\anaconda3\envs\new_env1\lib\json_init
.py", line 346, in loads return _default_decoder.decode(s) File “C:\Users\Admin\anaconda3\envs\new_env1\lib\json\decoder.py”, line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File “C:\Users\Admin\anaconda3\envs\new_env1\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)

      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "C:\Users\Admin\anaconda3\envs\new_env1\lib\site-packages\yfinance\multi.py", line 268, in _download_one
        File "C:\Users\Admin\anaconda3\envs\new_env1\lib\site-packages\yfinance\utils.py", line 104, in wrapper
          result = func(*args, **kwargs)
        File "C:\Users\Admin\anaconda3\envs\new_env1\lib\site-packages\yfinance\base.py", line 78, in history
          @utils.log_indent_decorator
        File "C:\Users\Admin\anaconda3\envs\new_env1\lib\site-packages\yfinance\utils.py", line 104, in wrapper
          result = func(*args, **kwargs)
        File "C:\Users\Admin\anaconda3\envs\new_env1\lib\site-packages\yfinance\scrapers\history.py", line 185, in history
        File "C:\Users\Admin\anaconda3\envs\new_env1\lib\site-packages\requests\models.py", line 978, in json
          raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
      requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

DEBUG Exiting download()

Bad data proof

No response

yfinance version

0.2.54

Python version

No response

Operating system

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 7
  • Comments: 24 (1 by maintainers)

Most upvoted comments

pip install --upgrade yfinance

And if that didn’t work:

pip install --upgrade --force-reinstall yfinance

I ran into a similar problem where running print(yf.__version__) returned the older version 0.2.48 even after executing pip install --upgrade --force-reinstall yfinance. I discovered that the updated version (0.2.54) was correctly installed in my repository’s .venv/Lib/site-packages folder, but I was inadvertently using a different virtual environment during runtime.

To diagnose the issue, I added print(yf.__file__) to my script, which revealed the path of the imported package. This made it clear that my active environment was not the one containing the latest version of yfinance.

Once I switched to the correct project virtual environment, everything worked as expected.

I was getting the same issue; however, seems to be an issue with user agent. Try updating the data.py and utils.py files within yfinance to the following:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36

This fixed the issue for me, now I can pull data again.

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

Then restart the kernel.

Let me know it works or not (worked for me)

Only reply if you have issue with latest version.

Try manually changing user-agent here (need to edit code): https://github.com/ranaroussi/yfinance/blob/403607c721c12c06a24fb03d9eb973854b408926/yfinance/data.py#L64