Fix get_data_yahoo from Pandas Datareader

What will we cover?

If you use get_data_yahoo from Pandas Datareader and it suddenly stopped working, then we will look at how to fix.

The Error and Problem

Consider this code.

import pandas_datareader as pdr
from datetime import datetime

data = pdr.get_data_yahoo('^GSPC', datetime(1970, 1, 1))

It has been working up until now. But suddenly it writes.

Traceback (most recent call last):
  File "/Users/rune/PycharmProjects/TEST/", line 4, in <module>
    data = pdr.get_data_yahoo('^GSPC', datetime(1970, 1, 1))
  File "/Users/rune/PycharmProjects/TEST/venv/lib/python3.8/site-packages/pandas_datareader/", line 86, in get_data_yahoo
    return YahooDailyReader(*args, **kwargs).read()
  File "/Users/rune/PycharmProjects/TEST/venv/lib/python3.8/site-packages/pandas_datareader/", line 253, in read
    df = self._read_one_data(self.url, params=self._get_params(self.symbols))
  File "/Users/rune/PycharmProjects/TEST/venv/lib/python3.8/site-packages/pandas_datareader/yahoo/", line 153, in _read_one_data
    resp = self._get_response(url, params=params)
  File "/Users/rune/PycharmProjects/TEST/venv/lib/python3.8/site-packages/pandas_datareader/", line 181, in _get_response
    raise RemoteDataError(msg)
pandas_datareader._utils.RemoteDataError: Unable to read URL:^GSPC/history?period1=10800&period2=1627523999&interval=1d&frequency=1d&filter=history
Response Text:
b'<!DOCTYPE html>\n  <html lang="en-us"><head>\n  <meta http-equiv="content-type" content="text/html; charset=UTF-8">\n      <meta charset="utf-8">\n      <title>Yahoo</title>\n      <meta name="viewport" content="width=device-width,initial-scale=1,minimal-ui">\n      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n      <style>\n  html {\n      height: 100%;\n  }\n  body {\n      background: #fafafc url( 50% 50%;\n      background-size: cover;\n      height: 100%;\n      text-align: center;\n      font: 300 18px "helvetica neue", helvetica, verdana, tahoma, arial, sans-serif;\n  }\n  table {\n      height: 100%;\n      width: 100%;\n      table-layout: fixed;\n      border-collapse: collapse;\n      border-spacing: 0;\n      border: none;\n  }\n  h1 {\n      font-size: 42px;\n      font-weight: 400;\n      color: #400090;\n  }\n  p {\n      color: #1A1A1A;\n  }\n  #message-1 {\n      font-weight: bold;\n      margin: 0;\n  }\n  #message-2 {\n      display: inline-block;\n      *display: inline;\n      zoom: 1;\n      max-width: 17em;\n      _width: 17em;\n  }\n      </style>\n  <script>\n    document.write(\'<img src="//\'+new Date().getTime()+\'&src=aws&err_url=\'+encodeURIComponent(document.URL)+\'&err=%<pssc>&test=\'+encodeURIComponent(\'%<{Bucket}cqh[:200]>\')+\'" width="0px" height="0px"/>\');var beacon = new Image();beacon.src="//"+new Date().getTime()+"&src=aws&err_url="+encodeURIComponent(document.URL)+"&err=%<pssc>&test="+encodeURIComponent(\'%<{Bucket}cqh[:200]>\');\n  </script>\n  </head>\n  <body>\n  <!-- status code : 404 -->\n  <!-- Not Found on Server -->\n  <table>\n  <tbody><tr>\n      <td>\n      <img src="" alt="Yahoo Logo">\n      <h1 style="margin-top:20px;">Will be right back...</h1>\n      <p id="message-1">Thank you for your patience.</p>\n      <p id="message-2">Our engineers are working quickly to resolve the issue.</p>\n      </td>\n  </tr>\n  </tbody></table>\n  </body></html>'

What to do?

The fix

There has been a breaking change and you need to update your Pandas Datareader.

You can upgrade to the newest version as follows.

pip install --upgrade pandas-datareader

It should update it to version 0.10.0 or later.

Then the code should work again.

19 Replies to “Fix get_data_yahoo from Pandas Datareader”

  1. While using my python script that uses pandas-DataReader v10 & pandas v1.3.3 get_data_yahoo(), when it first starts off it will show the last 5 days correctly because I am tailing this for the last 5 days, then after about a minute or two it changes to what you see below, I am using python 3.7.10 The date moves back 2 weeks and the volume from the last 4 days is off a lot, the current day is always correct ok

    I run my script on linux using the “watch -n1

    Code below
    def get_data(tickers):
    df = pdr.get_data_yahoo(tickers)
    return df

    for df in tickers:
    df = get_data(df) # this function retrieve’s stock information from yahoo finance
    df = pd.DataFrame(df.Close)

    #1 — works correctly Close
    Date Close
    2021-08-15 11.2500
    2021-09-16 9.9600
    2021-09-17 11.0600
    2021-09-20 11.7300
    2021-09-21 13.7001

    #2 — doesn’t work correctly Close
    Date Close
    2021-08-31 5.9600
    2021-09-01 7.4000
    2021-09-02 6.4900
    2021-09-03 6.7000
    2021-09-21 13.7001

    how can anyone help me

    1. Hi Frank,

      It looks like you have a list of Tickers you iterate over. You get the data for all of the and print the last retrieved data.

      The line taking Close in a DataFrame is maybe not needed?

      What is the goal here? For each iteration see the last five days of the specific ticket?

      If you share the list of tickers you are looking at and the full code I can take a look at it.

  2. I am getting information for one stock and that is the closing price and volume and I am using pandas-datareader get_data_yahoo() function, when I first run the stock one time it looks like the first photo, but what I am doing is using the “watch -n1 ” to get updates every 1 to 5 seconds so I get live updates, but after some time the data coming back goes back to September 09 2021 – August 31, 2021 like the second photo and the volume numbers don’t make any sense they are going into the billions, I have tried everything, different version of python3 + different versions of pip3 and pandas and pandas-datareader, the question is why does it keep going back to the last two weeks and why is my volume messed up, except for the current day., it only took 6 minutes for it to change to photo two

    1. I think this will do what you want:

      import pandas_datareader as pdr
      from datetime import datetime, timedelta

      while True:
      df = pdr.get_data_yahoo('AAPL', datetime.utcnow() - timedelta(days=7))

    1. Hi Bob,
      Just make sure we have installed in the right environment.

      Try to execute:
      import pandas_datareader as pdr

      It should output: 0.10.0

      If not, it is not installed (upgraded) in the right environment.

      What environment are you using?

  3. I am using Python 2.7 because it is what the author of an instruction video to scrape finance data from yahoo uses but I guess I’m gonna have to upgrade to Python 3 because I only have pandas 0.8.1.

  4. I am using Spyder. I tried updating pandas but it said I already had the latest version so I guess 0.8.1 is the latest version for Python 2.7.

  5. Hi, how can I check the version of pandas-datareader? I am using Anaconda distribution. After struggling for hours, I finally figured out how to install pandas-datareader (need to use conda install -c anaconda pandas-datareader in Anaconda Prompt).

    However I still get the “Unable to read URL” error. I tried to check the datareader version using “print(dpr.__version__) but it says that there is no attribute ‘__version__’. Please help.

    1. Hi Alex,

      If you run this:

      import pandas_datareader as pdr

      In a cell and it does give you no attribute error, then you can run the following in a cell:

      !pip freeze
      Then you need to find the line with


      It is ordered, so you should be able to locate it. (my output gives it for version 0.10.0, your’s might be different).

  6. Hello Rune, I’m unable to get multiple tickers. It keeps giving me this error

    ValueError Traceback (most recent call last)
    /tmp/ipykernel_67023/ in
    2 start = dt.datetime(2022, 1, 1)
    —-> 4 data = pdr.get_data_yahoo(tickers, start)

    /usr/local/lib/python3.8/dist-packages/pandas_datareader/ in get_data_yahoo(*args, **kwargs)
    79 def get_data_yahoo(*args, **kwargs):
    —> 80 return YahooDailyReader(*args, **kwargs).read()

    /usr/local/lib/python3.8/dist-packages/pandas_datareader/ in read(self)
    256 df = self._dl_mult_symbols(self.symbols.index)
    257 else:
    –> 258 df = self._dl_mult_symbols(self.symbols)
    259 return df

    /usr/local/lib/python3.8/dist-packages/pandas_datareader/ in _dl_mult_symbols(self, symbols)
    283 stocks[sym] = df_na
    284 if PANDAS_0230:
    –> 285 result = concat(stocks, sort=True).unstack(level=0)
    286 else:
    287 result = concat(stocks).unstack(level=0)

    /usr/local/lib/python3.8/dist-packages/pandas/core/ in unstack(self, level, fill_value)
    8411 from pandas.core.reshape.reshape import unstack
    -> 8413 result = unstack(self, level, fill_value)
    8415 return result.__finalize__(self, method=”unstack”)

    /usr/local/lib/python3.8/dist-packages/pandas/core/reshape/ in unstack(obj, level, fill_value)
    476 if isinstance(obj, DataFrame):
    477 if isinstance(obj.index, MultiIndex):
    –> 478 return _unstack_frame(obj, level, fill_value=fill_value)
    479 else:
    480 return obj.T.stack(dropna=False)

    /usr/local/lib/python3.8/dist-packages/pandas/core/reshape/ in _unstack_frame(obj, level, fill_value)
    499 def _unstack_frame(obj, level, fill_value=None):
    500 if not obj._can_fast_transpose:
    –> 501 unstacker = _Unstacker(obj.index, level=level)
    502 mgr = obj._mgr.unstack(unstacker, fill_value=fill_value)
    503 return obj._constructor(mgr)

    /usr/local/lib/python3.8/dist-packages/pandas/core/reshape/ in __init__(self, index, level, constructor)
    138 )
    –> 140 self._make_selectors()
    142 @cache_readonly

    /usr/local/lib/python3.8/dist-packages/pandas/core/reshape/ in _make_selectors(self)
    191 if mask.sum() 192 raise ValueError(“Index contains duplicate entries, cannot reshape”)
    194 self.group_index = comp_index

    ValueError: Index contains duplicate entries, cannot reshape

  7. i have the same error :
    ticker = [‘AAPL’]
    start = dt.datetime(2020, 1, 1)
    data = pdr.get_data_yahoo(ticker, start)
    ValueError: Index contains duplicate entries, cannot reshape

    1. It should work.
      Make sure you have the right formatting.

      import pandas_datareader as pdr
      import datetime as dt

      ticker = ["AAPL"]
      start = dt.datetime(2020, 1, 1)
      data = pdr.get_data_yahoo(ticker, start)

      If this does not work – make sure you have the right version of pandas datareader.

  8. Hi Rune , i have the same problem

    tickers = [‘AAPL’ ‘MSFT’]
    start = dt.datetime(2020, 1, 1)
    data = pdr.get_data_yahoo(tickers, start)


    i i insert tickers ‘ValueError: Index contains duplicate entries, cannot reshape?

    but if in tickers i insert ‘GBPUSD=X’, ‘EURGBP=X’ this is ok

Leave a Reply Cancel reply

Exit mobile version