Reputation: 1
I'm trying to get the live prices, previous close, and day's range with yahoo_fin's get_quote_table. It's been working with these errors occurring some of the time, but my program is able ... up until now. Today, I've constantly been getting these errors.
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)
I've also been running this bot on Heroku, and the same issue occurs. What could be causing this issue? Please help.
Edit: This error happens randomly. Sometimes, a certain ticker will fail, and another time, it'll work. However, today, it's been hectic and has been happening every time my bot starts up.
Upvotes: 0
Views: 821
Reputation: 764
It seems like one of two things has happened: something is wrong with YF's service or (more likely) they're actively trying to limit the number of people hitting their endpoints programmatically. The reason you're getting a JSONDecodeError
is that there's a 404 error:
You can hack your way around it though with a while loop and try / except block:
while True:
try:
# your code here
break
except ValueError: # ValueError will catch the JSONDecodeError
continue
Upvotes: 1