'Pandas_DataReader not working with Yahoo Finance API

I started working on a project a month ago to try and predict future stock prices using historical data. The project was going fine and I decided to take a small break to upgrade my PC. Well, I tried checking out my code after finishing the computer but now I'm running into a bunch of errors concerning pulling data from Yahoo Finance API. My friend is working on the same project and he said he isn't encountering any issues in the code so I think there's something wrong with my code environment. I'm not sure what to do since I'm pretty new to coding but I'm hoping someone can help me with the section of code below:

import pandas_datareader as web
import datetime as dt

# Load Data

symbols = 'NIO'

start = dt.datetime(2012,1,1)
end = dt.datetime(2020,1,1)

data = web.DataReader(symbols, 'yahoo', start, end)

Here is the error code I get in return:

RemoteDataError                           Traceback (most recent call last)
d:\Documents\Coding\laplaces_daemon\OneDayPredictor.py in 
     17 end = dt.datetime(2020,1,1)
     18 
---> 19 data = web.DataReader(symbols, 'yahoo', start, end)
     20 
     21 # Prepare Data

~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    197                 else:
    198                     kwargs[new_arg_name] = new_arg_value
--> 199             return func(*args, **kwargs)
    200 
    201         return cast(F, wrapper)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_datareader\data.py in DataReader(name, data_source, start, end, retry_count, pause, session, api_key)
    374 
    375     if data_source == "yahoo":
--> 376         return YahooDailyReader(
    377             symbols=name,
    378             start=start,

~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_datareader\base.py in read(self)
    251         # If a single symbol, (e.g., 'GOOG')
    252         if isinstance(self.symbols, (string_types, int)):
--> 253             df = self._read_one_data(self.url, params=self._get_params(self.symbols))
    254         # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
    255         elif isinstance(self.symbols, DataFrame):

~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_datareader\yahoo\daily.py in _read_one_data(self, url, params)
    151         url = url.format(symbol)
    152 
--> 153         resp = self._get_response(url, params=params)
    154         ptrn = r"root\.App\.main = (.*?);\n}\(this\)\);"
    155         try:

~\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_datareader\base.py in _get_response(self, url, params, headers)
    179             msg += "\nResponse Text:\n{0}".format(last_response_text)
    180 
--> 181         raise RemoteDataError(msg)
    182 
    183     def _get_crumb(self, *args):

RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/NIO/history?period1=1325408400&period2=1577955599&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(https://s.yimg.com/nn/img/sad-panda-201402200631.png) 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="//geo.yahoo.com/b?s=1197757129&t=\'+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="//bcn.fp.yahoo.com/p?s=1197757129&t="+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="https://s.yimg.com/rz/p/yahoo_frontpage_en-US_s_f_p_205x58_frontpage.png" 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>'


Solution 1:[1]

I don't know if it helps but yesterday I saw five questions for similar problem in module yfinance.

It seems Yahoo changed something on pages and it needs changes in modules.

For yfinance helps installing the newest version.

Maybe this module needs also newer version.
If they didn't create newer version then you will have to wait some time for newer version.

Solution 2:[2]

I also used to download data through pandas_datareader for Yahoo! But I ran into the same issues a while ago, and it was never fixed. So now, I just use the yfinance module. It's a bit different, but here's the code I use as an example:

import yfinance as yf
start = '2014-01-01'
end = '2022-01-01'
symbol = 'XLE'
stock_data = yf.Ticker(symbol)
stock_data = stock_data.history(start=start, end=end) 
[['Open','High','Low','Close']]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 furas
Solution 2 César Padilla