为什么从 Yahoo 财务模块下载数据时出现 JSONDecodeError
Why am I getting a JSONDecodeError while downloading data from Yahoo finance module
我是 Python 的新手,我写了一段简单的代码来从 yfinance 模块下载给定股票代码的历史数据。该代码已 运行 数周,最近,它开始抛出以下异常。这是代码:
data = yf.download("ibm", start="1/1/2017", end="1/6/2021")
这里是错误:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Python\Python39\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "C:\Python\PythonLearning\venv\lib\site-packages\multitasking\__init__.py", line 102, in _run_via_pool
return callee(*args, **kwargs)
File "C:\Python\PythonLearning\venv\lib\site-packages\yfinance\multi.py", line 167, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "C:\Python\PythonLearning\venv\lib\site-packages\yfinance\multi.py", line 179, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "C:\Python\PythonLearning\venv\lib\site-packages\yfinance\base.py", line 157, in history
data = data.json()
File "C:\Python\PythonLearning\venv\lib\site-packages\requests\models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\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)
这是一个已知问题,根据 GitHub 存储库的 Issue #777。
,最新版本的 yfinance
模块 (0.1.63) 已修复
将您的 yfinance
模块更新到 0.1.63 或更高版本。
我是 Python 的新手,我写了一段简单的代码来从 yfinance 模块下载给定股票代码的历史数据。该代码已 运行 数周,最近,它开始抛出以下异常。这是代码:
data = yf.download("ibm", start="1/1/2017", end="1/6/2021")
这里是错误:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
self.run()
File "C:\Python\Python39\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)
File "C:\Python\PythonLearning\venv\lib\site-packages\multitasking\__init__.py", line 102, in _run_via_pool
return callee(*args, **kwargs)
File "C:\Python\PythonLearning\venv\lib\site-packages\yfinance\multi.py", line 167, in _download_one_threaded
data = _download_one(ticker, start, end, auto_adjust, back_adjust,
File "C:\Python\PythonLearning\venv\lib\site-packages\yfinance\multi.py", line 179, in _download_one
return Ticker(ticker).history(period=period, interval=interval,
File "C:\Python\PythonLearning\venv\lib\site-packages\yfinance\base.py", line 157, in history
data = data.json()
File "C:\Python\PythonLearning\venv\lib\site-packages\requests\models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\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)
这是一个已知问题,根据 GitHub 存储库的 Issue #777。
,最新版本的yfinance
模块 (0.1.63) 已修复
将您的 yfinance
模块更新到 0.1.63 或更高版本。