dpguthrie / dpguthrie/yahooquery
Wrong handling of missing ESG data
- Dominant language
- Python
- Stars
- 920
- Forks
- 164
- PR merge metrics
- No merged PRs in 30d
Description
If the ESG data are missing at Yahoo, like with 'aalb.as' you are getting error messages
````
>>> from yahooquery import Ticker
>>> aapl = Ticker('aalb.as')
>>> aapl.esg_scores
Traceback (most recent call last):
File "/home/rudy/.local/lib/python3.10/site-packages/yahooquery/base.py", line 1217, in _construct_data
data = json[response_field]["result"][0][addl_key]
KeyError: 'esgScores'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in
File "/home/rudy/.local/lib/python3.10/site-packages/yahooquery/ticker.py", line 264, in esg_scores
return self._quote_summary(["esgScores"])
File "/home/rudy/.local/lib/python3.10/site-packages/yahooquery/ticker.py", line 101, in _quote_summary
data = self._get_data(key="quoteSummary", params=params, **kwargs)
File "/home/rudy/.local/lib/python3.10/site-packages/yahooquery/base.py", line 1088, in _get_data
data = self._sync_requests(response_field, urls, params, **kwargs)
File "/home/rudy/.local/lib/python3.10/site-packages/yahooquery/base.py", line 1185, in _sync_requests
data[symbol] = self._construct_data(json, response_field, **kwargs)
File "/home/rudy/.local/lib/python3.10/site-packages/yahooquery/base.py", line 1224, in _construct_data
json[response_field]["result"][addl_key]
TypeError: list indices must be integers or slices, not str
>>>
```
The version of `yahooquery` is `2.3.2`
The expected behavior would be an error free handling of missing ESG data such that the user can detect the missing data and take measure for further processing.
Examples of other stocks with the same problem are 'gnrc', 'hex.ol' or 'waf.de'.
Probably this error also occurs in case of other modules then 'esg_scores' with missing data
Contributor guide
Research direction
Start in yahooquery/ticker.py at the esg_scores entry point, then inspect yahooquery/base.py around _construct_data and the quote-summary request path shown in the traceback. Reproduce the missing-data case with aalb.as or another listed symbol and verify that the result is error-free while still allowing callers to detect missing ESG data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100