Skip to content

Commit

Permalink
Merge pull request #1833 from ange-daumal/json-fix
Browse files Browse the repository at this point in the history
Fix JSON error handling
  • Loading branch information
ValueRaider authored Jan 19, 2024
2 parents 7af789f + 06fd351 commit 2630c66
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions yfinance/scrapers/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,11 @@ def _fetch_complementary(self, proxy):

json_str = self._data.cache_get(url=url, proxy=proxy).text
json_data = json.loads(json_str)
if json_data["timeseries"]["error"] is not None:
raise YFinanceException("Failed to parse json response from Yahoo Finance: " + json_data["error"])
json_result = json_data.get("timeseries") or json_data.get("finance")
if json_result["error"] is not None:
raise YFinanceException("Failed to parse json response from Yahoo Finance: " + str(json_result["error"]))
for k in keys:
keydict = json_data["timeseries"]["result"][0]
keydict = json_result["result"][0]
if k in keydict:
self._info[k] = keydict[k][-1]["reportedValue"]["raw"]
else:
Expand Down

0 comments on commit 2630c66

Please sign in to comment.