yahooquery icon indicating copy to clipboard operation
yahooquery copied to clipboard

Wrong handling of missing ESG data

Open RudyNL opened this issue 2 years ago • 1 comments

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 "<stdin>", line 1, in <module>
  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

RudyNL avatar Jul 26 '23 06:07 RudyNL

This may be resolved in 2.3.3 - test it out:

In [11]: t = yq.Ticker('aalb.as')

In [12]: data = t.esg_scores

In [13]: data
Out[13]: {'aalb.as': 'No fundamentals data found for any of the summaryTypes=esgScores'}

dpguthrie avatar Oct 28 '23 17:10 dpguthrie