是什么原因导致此yahoo_fin get_quote_table错误?

时间:2020-06-29 15:51:01

标签: json python-3.x finance yahoo-finance computational-finance

我正在尝试使用yahoo_fin的get_quote_table获取实时价格,之前的收盘价和当日价格范围。它一直在处理某些时间出现的这些错误,但是到目前为止,我的程序仍然可以运行。今天,我一直在不断遇到这些错误。

File "bot.py", line 120, in start
    price_opens[i] = get_quote_table(all_tickers[i])["Previous Close"]
  File "C:\Users\NAME\AppData\Local\Programs\Python\Python36\lib\site-packages\yahoo_fin\stock_info.py", line 202, in get_quote_table
    quote_price = pd.DataFrame(["Quote Price", get_live_price(ticker)]).transpose()
  File "C:\Users\NAME\AppData\Local\Programs\Python\Python36\lib\site-packages\yahoo_fin\stock_info.py", line 425, in get_live_price
    df = get_data(ticker, end_date = pd.Timestamp.today() + pd.DateOffset(10))
  File "C:\Users\NAME\AppData\Local\Programs\Python\Python36\lib\site-packages\yahoo_fin\stock_info.py", line 78, in get_data
    raise AssertionError(resp.json())
  File "C:\Users\NAME\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\NAME\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Users\NAME\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\NAME\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我也在Heroku上运行了该bot,并且发生了同样的问题。 是什么导致此问题?请帮忙。

编辑:此错误是随机发生的。有时候,某个股票行情指示器会失败,而另一次它将行得通。但是,今天,它忙得不可开交,每次我的机器人启动时都在发生。

1 个答案:

答案 0 :(得分:0)

似乎发生了两件事之一:YF的服务出了点问题,或者(很可能)他们正在积极尝试以编程方式限制到达终点的人数。您得到JSONDecodeError的原因是存在404错误:

enter image description here

虽然可以使用while循环来破解它,然后尝试/除了块:

while True:
    try:
        # your code here
        break
    except ValueError: # ValueError will catch the JSONDecodeError
        continue