20

I am trying to download historical data from Yahoo using Pandas datareader. This is the code that I normally use:

import pandas_datareader as pdr
df = pdr.get_data_yahoo('SPY')

However, I started receiving this error today: RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/SPY/history?period1=1467511200&period2=1625277599&interval=1d&frequency=1d&filter=history

Does anyone know how to solve it?

Thank you very much in advance!

Rubén
  • 34,714
  • 9
  • 70
  • 166
Martingale
  • 511
  • 1
  • 6
  • 15
  • 1
    Looks like a temporary error at the "Remote" end which Yahoo will fix soon. Before asking here, check similar issues at https://github.com/pydata/pandas-datareader/issues?q=RemoteDataError%3A+Unable+to+read+URL – Devon Jul 03 '21 at 01:20
  • I also ran into error roughly 2 weeks ago. It is a possibility they have (again) discontinued their API – kawingkelvin Jul 10 '21 at 14:57
  • @kawingkelvin Oh no! I was enjoying using it. Any good alternatives/workarounds that you know of? – SamTheProgrammer Jul 11 '21 at 16:35

2 Answers2

25

This has been answered here already. Since now requires headers, pandas and pandas-datareader must be updated. Other libraries working with pdr might give you issues until gets updated or you modify the part of the code which retreives data.

Have a nice day ;).

pip install --upgrade pandas
pip install --upgrade pandas-datareader
2

If you are using Colab, run:

!pip install --upgrade pandas-datareader

...
Installing collected packages: pandas-datareader
  Attempting uninstall: pandas-datareader
    Found existing installation: pandas-datareader 0.9.0
    Uninstalling pandas-datareader-0.9.0:
      Successfully uninstalled pandas-datareader-0.9.0
Successfully installed pandas-datareader-0.10.0
WARNING: The following packages were previously imported in this runtime:
  [pandas_datareader]
You must restart the runtime in order to use newly installed versions.

Go to Runtime -> Restart runtime. Then you can import pandas_datareader and check that it's the right version:

import pandas_datareader
pandas_datareader.__version__  # Should show 0.10.0
kris
  • 23,024
  • 10
  • 70
  • 79