yFinance 的 JSON 解码错误 [JSONDecodeError: Expecting value: line 1 column 1 (char 0)] [英] JSON Decode Error with yFinance [JSONDecodeError: Expecting value: line 1 column 1 (char 0)]

查看:320
本文介绍了yFinance 的 JSON 解码错误 [JSONDecodeError: Expecting value: line 1 column 1 (char 0)]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been using yfinance for the last several weeks to pull historical data on a number of stocks. I normally run the program at the end of each week to store data for that week, but this problem error just randomly starting occurring this past week. Below is a simple example of calling for historical price data for MMM. However, the same error occurs for option contract methods.

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)

推荐答案

我是 Stack Overflow 的新手,所以我无法投票,但我遇到了类似的问题.看到答案@Barmar 离开后,我去了 yfinance github 并且作者建议使用 pip install yfinance --upgrade --no-cache-dir 来解决任何当前问题.对我有用,我希望它对你有用,因为我们似乎有类似的问题:]

Im new to Stack Overflow so I couldn't upvote but I was having a similar issue. After seeing the answer @Barmar left I went to the yfinance github and the author recommends using pip install yfinance --upgrade --no-cache-dir to resolve any current issues. Worked for me, I hope it works for you since we seem to have similar issues :]

这篇关于yFinance 的 JSON 解码错误 [JSONDecodeError: Expecting value: line 1 column 1 (char 0)]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆