json解码错误,带有yfinance[jsondecodeerror:预期值:第1行第1列(字符0)]

4ktjp1zp  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(260)

在过去的几周里,我一直在使用yfinance提取一些股票的历史数据。我通常在每周结束时运行该程序以存储该周的数据,但这个问题错误只是在过去的一周随机开始出现。下面是调用mmm历史价格数据的简单示例。然而,期权合约方法也会出现同样的错误。

import yfinance as yf
mmm = yf.Ticker('MMM')
mmm.history()

错误堆栈:

JSONDecodeError                           Traceback (most recent call last)
<ipython-input-6-68e978705cca> in <module>
      1 mmm = yf.Ticker('MMM')
----> 2 mmm.history()

~/opt/anaconda3/lib/python3.8/site-packages/yfinance/base.py in history(self, period, interval, start, end, prepost, actions, auto_adjust, back_adjust, proxy, rounding, tz,**kwargs)
    155                                "Our engineers are working quickly to resolve "
    156                                "the issue. Thank you for your patience.")
--> 157         data = data.json()
    158 
    159         # Work with errors

~/opt/anaconda3/lib/python3.8/site-packages/requests/models.py in json(self,**kwargs)
    896                     # used.
    897                     pass
--> 898         return complexjson.loads(self.text,**kwargs)
    899 
    900     @property

~/opt/anaconda3/lib/python3.8/json/__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook,**kw)
    355             parse_int is None and parse_float is None and
    356             parse_constant is None and object_pairs_hook is None and not kw):
--> 357         return _default_decoder.decode(s)
    358     if cls is None:
    359         cls = JSONDecoder

~/opt/anaconda3/lib/python3.8/json/decoder.py in decode(self, s, _w)
    335 
    336         """
--> 337         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338         end = _w(s, end).end()
    339         if end != len(s):

~/opt/anaconda3/lib/python3.8/json/decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
8ulbf1ek

8ulbf1ek1#

我是新来的堆栈溢出,所以我不能向上投票,但我有一个类似的问题。在看到@barmar left的答案后,我去了yfinance github,作者建议使用 pip install yfinance --upgrade --no-cache-dir 解决任何当前问题。对我有效,我希望对你有效,因为我们似乎有类似的问题:]

相关问题