Issue with Pandas Datareader - Yahoo Financee

In pandas Datareader yahoo finance is not working rest of the option are working and I have tried all the possible ways shown on the internet. I want Indian Stock Dataset Form Yahoo Finance

Please copy/paste the traceback inline as text between ;code fences",
not as a screenshot. Example:

 ```
 your pasted text
 goes here
 ```

There’s a </> button in the compose with to make a pair of fences.

We can’t copy/paste from a screenshot, and they are troublesome for the
visually impaired.

In pandas Datareader yahoo finance is not working rest of the option are working and I have tried all the possible ways shown on the internet. I want Indian Stock Dataset Form Yahoo Finance

Looks lik you’re using this:
https://pandas-datareader.readthedocs.io/en/latest/readers/yahoo.html

The error suggests that the data received from yahoo Finance are not in
the format expected by the reader, because the long expression:

 data = j["content"]["dispatcher"]["stores"]["HistoricalPriceStore"]

hits a string instead of a mapping at some point. It is hard to offer
more detail at this point because we do not know that’s in the variable j.

I recommend editing that particular file directly, and putting these
lines just above the data = j[.....] line:

 from pprint import pformat
 import sys
 print("j =", pformat(j), file=sys.stderr)

That should print out what’s in j, letting you see what’s wrong with
the indexing stuff. Maybe Yahoo have changed their data format.

For what it’s worth, your code fails for me also:

 [~]fleet2*> py3
 Python 3.10.6 (main, Aug 11 2022, 13:47:18) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import pandas_datareader as pdr
 >>> pdr.get_data_yahoo('TSLA')
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module> File "/Users/cameron/var/venv/3.10.6_1-homebrew/lib/python3.10/site-packages/pandas_datareader/data.py", line 80, in get_data_yahoo
     return YahooDailyReader(*args, **kwargs).read()
   File "/Users/cameron/var/venv/3.10.6_1-homebrew/lib/python3.10/site-packages/pandas_datareader/base.py", line 253, in read
     df = self._read_one_data(self.url, params=self._get_params(self.symbols))
   File "/Users/cameron/var/venv/3.10.6_1-homebrew/lib/python3.10/site-packages/pandas_datareader/yahoo/daily.py", line 153, in _read_one_data
     data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
 TypeError: string indices must be integers
 >>>

I inserted the lines I suggest above and got this as the start of the
(enormous) data:

 j = {'_cr': '{"words":[246593948,894281469,1212026277,571263794],"sigBytes":16}',
  '_cs': '9153b501a123',
  'context': {'dispatcher': {'stores': 'U2FsdGVkX18ijP36b4/97KzP

so the "stores" part is indeed not a dict but instead a flat string.
Looking at it it looks like base64 data. Decoding it looks like binary
data in an unknown form. Do you need some API key or something before
Yahoo will give you something useful? I have little idea at this point.

Cheers,
Cameron Simpson cs@cskk.id.au

Thank you very much Mr. Simpson for your thoughts!!

Hi, your problem might stem from the fact that the Yfinance module has been updated recently - maybe you need to install the new version: yfinance · PyPI

Hi, you need to update your yfinance and than look in this part of documentation.

1 Like

You might have a look at the import statement. Willsgomes85 uses another one:
from pandas_datareader import data as pdr
This will probably solve your problem.