pandas-datareader icon indicating copy to clipboard operation
pandas-datareader copied to clipboard

Response format from Yahoo seems to have changed I keep getting this error.

Open yeison opened this issue 2 years ago • 98 comments

File "/Users/yeison/miniforge3/envs/tf-metal-0.6.0/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

yeison avatar Dec 17 '22 01:12 yeison

As work around you may try to use solution from https://pypi.org/project/yfinance/ title pandas_datareader override

DevAleksei avatar Dec 17 '22 06:12 DevAleksei

They started to encrypt the stores, looks like they encrypted with AES or something like that and now stores values comes as a string, not sure how to solve that

ivofernandes avatar Dec 17 '22 12:12 ivofernandes

Is there some way that I can implement a temporary solution using yfinance as an override and pull request it ?

raphi6 avatar Dec 17 '22 22:12 raphi6

Is there some way that I can implement a temporary solution using yfinance as an override and pull request it ?

>>> from pandas_datareader import data as pdr
>>> import yfinance as yf
>>> yf.pdr_override()
>>> y_symbols = ['SCHAND.NS', 'TATAPOWER.NS', 'ITC.NS']
>>> from datetime import datetime
>>> startdate = datetime(2022,12,1)
>>> enddate = datetime(2022,12,15)
>>> data = pdr.get_data_yahoo(y_symbols, start=startdate, end=enddate)

Source on StackOverflow

DenisOd91 avatar Dec 17 '22 23:12 DenisOd91

Is there some way that I can implement a temporary solution using yfinance as an override and pull request it ?

>>> from pandas_datareader import data as pdr
>>> import yfinance as yf
>>> yf.pdr_override()
>>> y_symbols = ['SCHAND.NS', 'TATAPOWER.NS', 'ITC.NS']
>>> from datetime import datetime
>>> startdate = datetime(2022,12,1)
>>> enddate = datetime(2022,12,15)
>>> data = pdr.get_data_yahoo(y_symbols, start=startdate, end=enddate)

Source on StackOverflow

Oh yeah I have used this but I meant fixing pandas-datareader as I have already submitted the code for my dissertation so I can't change my code directly, the only way I can change my code is by changing the library hehe. sorry for confusion

raphi6 avatar Dec 17 '22 23:12 raphi6

They started to encrypt the stores, looks like they encrypted with AES or something like that and now stores values comes as a string, not sure how to solve that

What are the stores? I will try anything to fix this as I have just submitted my interim dissertation and without this library, my code has no data :/ due to the nature of academia I dont think asking if the marker can override with yfinance will work

raphi6 avatar Dec 18 '22 14:12 raphi6

What are the stores? I will try anything to fix this as I have just submitted my interim dissertation and without this library, my code has no data :/ due to the nature of academia I dont think asking if the marker can override with yfinance will work

Then you are the best candidate to fix this library. j["context"]["dispatcher"]["stores"] response contains some encrypted data instead of plain object, so you may take a look at how this data is handled in yfinance, and migrate the code. Good luck.

DevAleksei avatar Dec 18 '22 14:12 DevAleksei

What are the stores? I will try anything to fix this as I have just submitted my interim dissertation and without this library, my code has no data :/ due to the nature of academia I dont think asking if the marker can override with yfinance will work

Then you are the best candidate to fix this library. j["context"]["dispatcher"]["stores"] response contains some encrypted data instead of plain object, so you may take a look at how this data is handled in yfinance, and migrate the code. Good luck.

With a stroke of magical programmer luck I have managed to migrate some code from yfinance where now the data is decrypted and I have tested on a small number of stocks I am able to get their data.

         I changed code in: pandas_datareader/yahoo/daily.py   Just adding a decryption function and making sure data is 
         handled correctly like before .

It took me all day as I have never worked on such a professional code base so far. But that leads to another issue now, How do I go about merging my solution or I guess I have to create a pull request now? I am not sure how this works!

pandas-datareader was checkedout locally to my IDE and I have made all the changes there, what do you suggest me to do? I am sure there are still things needed to be added to the codebase like requirements etc? idk this is my first time.

Thanks for any help.

raphi6 avatar Dec 18 '22 20:12 raphi6

File "/Users/yeison/miniforge3/envs/tf-metal-0.6.0/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 have found a fix, as stated in above comment. Do you know how about I will go creating a pull request? I just tried on my IDE and got permission denied? Any suggestions?

raphi6 avatar Dec 18 '22 21:12 raphi6

@raphi6 have you tried branching from the downloaded repository and then pushing your changes? It should say there's no upstream branch, by setting one you'll create a pull request.

mazalkov avatar Dec 18 '22 21:12 mazalkov

Ahh yes branching, I always forget. So now I will checkout pandas-datareader, create a branch and add my changes, create a pull request. And that should work?

raphi6 avatar Dec 18 '22 21:12 raphi6

Yes I think so, it may not be the best way of doing it but I do not currently know of a better one. By setting an upstream branch and pushing your branch to it, it should create the PR.

mazalkov avatar Dec 18 '22 21:12 mazalkov

Yes I think so, it may not be the best way of doing it but I do not currently know of a better one. By setting an upstream branch and pushing your branch to it, it should create the PR.

image

I just tried creating a new branch and commiting, pushing, then creating a PR and get the above, What did you mean by setting an upstream branch?

raphi6 avatar Dec 18 '22 22:12 raphi6

You may be trying to push directly to master, which only the repo owners will have permission for (although it is advised never to push directly to master in any case). To not take up replies in the thread, I would recommend looking into the process of opening a PR on GitHub for another repo using online resources:

Link 1 Link 2 LInk 3

Apologies I can't be any more help, quite new to Git in terms of contributing to 3rd party repos.

mazalkov avatar Dec 18 '22 22:12 mazalkov

I've opened a pull request with working code, be sure to check it out if it works for you guys.

raphi6 avatar Dec 19 '22 09:12 raphi6

Hi, @raphi6 , I can confirm it works perfectly fine. Thanks a lot for the quick fix! Let's see if they approve the pull request.

For reference, I cloned your pull request and installed it using the following sequence of commands (in Ubuntu 20.04):

git clone https://github.com/raphi6/pandas-datareader.git
git checkout 'Yahoo!_Issue#952'
conda uninstall pandas-datareader
conda install pycryptodome pycryptodomex
python setup.py install --record installed_files.txt

The --record argument in the install command is to get a list of installed files, so that it is easy to uninstall in the future (following this SO thread). The pycrypto* files are dependencies I has to install to make it work.

joanlofe avatar Dec 19 '22 17:12 joanlofe

Hi, @raphi6 , I can confirm it works perfectly fine. Thanks a lot for the quick fix! Let's see if they approve the pull request.

For reference, I cloned your pull request and installed it using the following sequence of commands (in Ubuntu 20.04):

git clone https://github.com/raphi6/pandas-datareader.git
git checkout 'Yahoo!_Issue#952'
conda uninstall pandas-datareader
conda install pycryptodome pycryptodomex
python setup.py install --record installed_files.txt

The --record argument in the install command is to get a list of installed files, so that it is easy to uninstall in the future (following this SO thread). The pycrypto* files are dependencies I has to install to make it work.

Can this be installed or implemented on Google Colabs?

pyproper avatar Dec 19 '22 22:12 pyproper

The following seems to work well on Google Colab.

%%shell
git clone https://github.com/raphi6/pandas-datareader.git
cd pandas-datareader 
git checkout 'Yahoo!_Issue#952'
pip install pycryptodome pycryptodomex
python setup.py install --record installed_files.txt

HiroshiOkada avatar Dec 20 '22 08:12 HiroshiOkada

The following seems to work well on Google Colab.

%%shell
git clone https://github.com/raphi6/pandas-datareader.git
cd pandas-datareader 
git checkout 'Yahoo!_Issue#952'
pip install pycryptodome pycryptodomex
python setup.py install --record installed_files.txt

/usr/local/lib/python3.8/dist-packages/pandas_datareader/base.py:272: SymbolWarning: Failed to read symbol: RemoteDataError: No data fetched using 'YahooDailyReader' I get this which started to be an issue a year or so ago and have been using this since then pip install git+https://github.com/pydata/pandas-datareader.git Is it possible to put them together?

pyproper avatar Dec 20 '22 15:12 pyproper

Hello - I've got a few complex scripts running in jupiter notebook pulling data from yahoo finance - what are the exact commands which need to be entered in order to regain access so that I dont get the "string indices must be integers" error ? much appreciated, thx for the help

nichaelwichterle1 avatar Dec 20 '22 17:12 nichaelwichterle1

The following seems to work well on Google Colab.

%%shell
git clone https://github.com/raphi6/pandas-datareader.git
cd pandas-datareader 
git checkout 'Yahoo!_Issue#952'
pip install pycryptodome pycryptodomex
python setup.py install --record installed_files.txt

/usr/local/lib/python3.8/dist-packages/pandas_datareader/base.py:272: SymbolWarning: Failed to read symbol: RemoteDataError: No data fetched using 'YahooDailyReader' I get this which started to be an issue a year or so ago and have been using this since then pip install git+https://github.com/pydata/pandas-datareader.git Is it possible to put them together?

@pyproper Yes, it is. You can use this:

 pip install git+https://github.com/raphi6/pandas-datareader.git@ea66d6b981554f9d0262038aef2106dda7138316

Notice I am using the commit hash here instead of a branch name, because it is Yahoo!_Issue#952 and there is an issue with hash characters when using pip this way.

joanlofe avatar Dec 20 '22 19:12 joanlofe

Thanks very much, all looks good now!

nichaelwichterle1 avatar Dec 20 '22 21:12 nichaelwichterle1

@pyproper Yes, it is. You can use this:

 pip install git+https://github.com/raphi6/pandas-datareader.git@ea66d6b981554f9d0262038aef2106dda7138316

Notice I am using the commit hash here instead of a branch name, because it is Yahoo!_Issue#952 and there is an issue with hash characters when using pip this way.

Perfect! Thank You

pyproper avatar Dec 20 '22 21:12 pyproper

@joanlofe

@pyproper Yes, it is. You can use this:

 pip install git+https://github.com/raphi6/pandas-datareader.git@ea66d6b981554f9d0262038aef2106dda7138316

Notice I am using the commit hash here instead of a branch name, because it is Yahoo!_Issue#952 and there is an issue with hash characters when using pip this way.

I had to use pip3 to install, but now have the following error:

Traceback (most recent call last): File "USP.py", line 6, in from pandas_datareader import data as pdr File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/init.py", line 5, in from .data import ( File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/data.py", line 11, in from pandas_datareader.av.forex import AVForexReader File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/av/init.py", line 5, in from pandas_datareader._utils import RemoteDataError File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/_utils.py", line 6, in from pandas_datareader.compat import is_number File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/compat/init.py", line 1, in from packaging import version ModuleNotFoundError: No module named 'packaging'

Thoughts?

KryptoEmman avatar Dec 20 '22 22:12 KryptoEmman

@KryptoEmman Have you tried pip install packaging and then repeat again?

joanlofe avatar Dec 21 '22 08:12 joanlofe

I've opened a pull request with working code, be sure to check it out if it works for you guys.

This fix by @raphi6 needs to be made a priority. Yahoo API is bricked through PDR.

CKDarling avatar Dec 21 '22 15:12 CKDarling

I've opened a pull request with working code, be sure to check it out if it works for you guys.

This fix by @raphi6 needs to be made a priority. Yahoo API is bricked through PDR.

Thank you! if anyone could get into contact with someone that can accept the PR, that would be great!

raphi6 avatar Dec 22 '22 12:12 raphi6

@KryptoEmman Have you tried pip install packaging and then repeat again?

@joanlofe I ran that command with pip3 not pip - running on MacOS - which ran successfully, but now getting the following different error: Traceback (most recent call last): File "USP.py", line 6, in import pandas_datareader as pdr File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/init.py", line 5, in from .data import ( File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/data.py", line 36, in from pandas_datareader.yahoo.actions import YahooActionReader, YahooDivReader File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/yahoo/actions.py", line 4, in from pandas_datareader.yahoo.daily import YahooDailyReader File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pandas_datareader/yahoo/daily.py", line 9, in from Crypto.Cipher import AES ModuleNotFoundError: No module named 'Crypto'

Clearly missing the required Crypto module using "pip3 install Crypto", but still getting the same error, so I'm guessing this must be from another package. Tried "pip3 install hashlib" which errors out with the exit code 1 and a message stating "unknown OS, please update setup.py" which leads me to think that some of these modules are only available for MacOS.

pip3 list outputs the following:

aes 1.2.0 certifi 2022.12.7 charset-normalizer 2.1.1 crypto 1.4.1 et-xmlfile 1.1.0 forex-python 1.8 idna 3.4 lxml 4.9.1 Naked 0.1.32 numpy 1.23.4 openpyxl 3.0.10 packaging 22.0 pandas 1.5.1 pandas-datareader 0+untagged.811.gea66d6b pip 22.3.1 python-dateutil 2.8.2 pytz 2022.6 PyYAML 6.0 requests 2.28.1 setuptools 65.5.0 shellescape 3.8.1 simplejson 3.17.6 six 1.16.0 urllib3 1.26.12

Thoughts? Thanks.

KryptoEmman avatar Dec 22 '22 17:12 KryptoEmman

@KryptoEmman Try this: pip3 install pycryptodome pycryptodomex

joanlofe avatar Dec 22 '22 20:12 joanlofe

@joanlofe

pip3 install pycryptodome pycryptodomex

Tried the command above but get the same result when I try to use pandas-reader with Yahoo: "ModuleNotFoundError: No module named 'Crypto'"

KryptoEmman avatar Dec 23 '22 20:12 KryptoEmman