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

Fail to download data from yahoo on 01/13/2023

Open yuzhipeter opened this issue 2 years ago • 10 comments

Hello,

Data download fails from yahoo finance. The error msg is

df = web.DataReader("SPY", data_source='yahoo', start='2020-01-01', end='2020-03-03', session = sesh) Traceback (most recent call last):

File "C:\Users\peter\AppData\Local\Temp/ipykernel_25324/3322276019.py", line 1, in df = web.DataReader("SPY", data_source='yahoo', start='2020-01-01', end='2020-03-03', session = sesh)

File "C:\Users\peter\anaconda3\lib\site-packages\pandas\util_decorators.py", line 207, in wrapper return func(*args, **kwargs)

File "C:\Users\peter\anaconda3\lib\site-packages\pandas_datareader\data.py", line 370, in DataReader return YahooDailyReader(

File "C:\Users\peter\anaconda3\lib\site-packages\pandas_datareader\base.py", line 253, in read df = self._read_one_data(self.url, params=self._get_params(self.symbols))

File "C:\Users\peter\anaconda3\lib\site-packages\pandas_datareader\yahoo\daily.py", line 231, in _read_one_data data = new_j['HistoricalPriceStore']

UnboundLocalError: local variable 'new_j' referenced before assignment

It was good yesterday, 01/12/2023. Thanks!

yuzhipeter avatar Jan 14 '23 05:01 yuzhipeter

Assume you installed pandas-datareader using this command pip install git+https://github.com/raphi6/pandas-datareader.git@ea66d6b981554f9d0262038aef2106dda7138316

Faced the same issue today, but based on this commit, overwrote these 3 files:

folder = /path/to/env/env-name/Lib/site-packages

1) pandas_datareader/tests/io/test_jsdmx.py
2) pandas_datareader/tests/yahoo/test_options.py
3) pandas_datareader/yahoo/daily.py

Working as expected, waiting for Issue #952 merge to main branch and a release soon.

devmsft-github avatar Jan 17 '23 22:01 devmsft-github

It works now. Thanks!

yuzhipeter avatar Jan 18 '23 04:01 yuzhipeter

@devmsft-github how did you overwrite the 3 files?

AnOniMaTe32 avatar Jan 19 '23 14:01 AnOniMaTe32

  1. Saved the 3 original files that came with the pip install to [filename]_orig.py
  2. from this commit, copied the content of the newest version of file_1
  3. Opened [file_1].py under /path/to/env/Lib/site-packages and pasted content from (2)
  4. Repeat for file_2 & file_3

devmsft-github avatar Jan 19 '23 20:01 devmsft-github

The new files are broken again with yahoo finance

df = web.DataReader("SPY", data_source='yahoo', start='2023-01-01', end='2023-01-13', session = sesh)

Error msg

Traceback (most recent call last):

File "C:\Users\peter\AppData\Local\Temp/ipykernel_27516/630144412.py", line 1, in df = web.DataReader("SPY", data_source='yahoo', start='2023-01-01', end='2023-01-13', session = sesh)

File "C:\Users\peter\anaconda3\lib\site-packages\pandas\util_decorators.py", line 207, in wrapper return func(*args, **kwargs)

File "C:\Users\peter\anaconda3\lib\site-packages\pandas_datareader\data.py", line 370, in DataReader return YahooDailyReader(

File "C:\Users\peter\anaconda3\lib\site-packages\pandas_datareader\base.py", line 253, in read df = self._read_one_data(self.url, params=self._get_params(self.symbols))

File "C:\Users\peter\anaconda3\lib\site-packages\pandas_datareader\yahoo\daily.py", line 227, in _read_one_data new_j = decrypt_cryptojs_aes(

File "C:\Users\peter\anaconda3\lib\site-packages\pandas_datareader\yahoo\daily.py", line 81, in decrypt_cryptojs_aes plaintext = unpad(plaintext, 16, style="pkcs7")

File "C:\Users\peter\anaconda3\lib\site-packages\Crypto\Util\Padding.py", line 92, in unpad raise ValueError("Padding is incorrect.")

ValueError: Padding is incorrect.

Thanks!

yuzhipeter avatar Jan 28 '23 18:01 yuzhipeter

This time went the route of yfinance as below

import yfinance as yf
yf.pdr_override()

then

data = yf.download(ticker, start=start_date, end=end_date, threads=False) # or threads=True

This works with raphi6's pandas-datareader fixes I suggested above, so all you need is yfinance.

devmsft-github avatar Jan 29 '23 18:01 devmsft-github

This still not working !!!

fouad09 avatar Feb 01 '23 15:02 fouad09

No update on this issue? Is pandas-datareader abandoned?

suaide avatar Feb 06 '23 12:02 suaide

pandas-datareader works as expected with the yfinance fix above.

What is not working?

devmsft-github avatar Feb 15 '23 03:02 devmsft-github

Hey there, The yfinance module offers an override of the yahoo finance from datareader. It only requires to add one line.

from pandas_datareader import data as pdr

import yfinance as yf
yf.pdr_override() # <== that's all it takes :-)

# download dataframe
data = pdr.get_data_yahoo("SPY", start="2017-01-01", end="2017-04-30")

You can check the comment on the official yfinance repo -> here

Hope it helps, it worked for me.

Luminilion avatar Mar 06 '23 11:03 Luminilion