pythonpandasdatareader

Unable to get stock data from yahoo with pandas_datareader


This is my code:

start = '2015-1-1'
end = '2020-12-31'
source = 'yahoo'

google = data.DataReader('GOOG', start=start, end=end, data_source=source).reset_index()

I was using this code till last month and it was working properly, after a month I tried this code and now this code is throwing me error:

Unable to read URL: https://finance.yahoo.com/quote/GOOG/history?period1=1420065000&period2=1609453799&interval=1d&frequency=1d&filter=history

I am not able to figure it out, can you please make me understand, why is this happening?


Solution

  • Yahoo! Finance has changed slightly their structure. Now requires headers for the data retreival on the http request. Once done works fine.

    For pandas & pandas-datareader which you'll need to upgrade them if you use it. (Which has been already sorted). Probably on all other packages using data from yahoo! such backtrader, etc, you'll need either upgrade or add headers on the yahoo! script to retrieve data :).

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

    Have a nice day ;).