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

yahoo finance not working

Open ghost opened this issue 3 years ago • 9 comments

I went through the example on the documentation and seems that is not working

from pandas_datareader import data

import pandas_datareader.data as web
import pandas as pd
import datetime as dt

df = web.DataReader('GE', 'yahoo', start='2019-09-10', end='2019-10-09')

Here is the error:


RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/GE/history?period1=1568084400&period2=1570676399&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>'

ghost avatar Nov 21 '21 08:11 ghost

The message is 404, page not found, but then it implies that the problem is temporary: "Our engineers are working quickly to resolve the issue".

The link worked for me just now (opened in Chrome).

On Sun, Nov 21, 2021 at 2:21 AM Moustafa Chatzouz @.***> wrote:

I went through the example on the documentation and seems that is not working

from pandas_datareader import data

import pandas_datareader.data as web import pandas as pd import datetime as dt

df = web.DataReader('GE', 'yahoo', start='2019-09-10', end='2019-10-09')

Here is the error:

RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/GE/history?period1=1568084400&period2=1570676399&interval=1d&frequency=1d&filter=history Response Text: b'\n

\n \n \n Yahoo\n \n \n \n \n \n \n \n \n \n \n \n \n
\n Yahoo Logo\n

Will be right back...

\n

Thank you for your patience.

\n

Our engineers are working quickly to resolve the issue.

\n
\n '

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pydata/pandas-datareader/issues/916, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD3AQGJ5TH2A7GHBJIPKAS3UNCTZFANCNFSM5IO4PPIA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

paulmcq avatar Nov 21 '21 14:11 paulmcq

@paulmcq That's anything but a temporary problem. I am getting this type of error for months now. My guess is that something is going on with the API call limits. Otherwise, not sure I can understand the source of the problem.

The question is not if one can open the link, but if it was possible to download the prices. The link works for too if I copy and paste it to chrome.

ghost avatar Nov 21 '21 15:11 ghost

Still not working on 2021/12/12. the url can be opened and cannot be called by colab. Error message:

Unable to read URL: https://finance.yahoo.com/quote/GE/history?period1=1568088000&period2=1570679999&interval=1d&frequency=1d&filter=history

Please help!!

kaispace30098 avatar Dec 12 '21 18:12 kaispace30098

@msh855 Would you like to try yfnance package to fetch data from yahoo finance api?

!pip install yfinance import yfinance as yf start = "2020-12-12" end = '2021-12-12' btcusd= yf.download('BTC-USD',start,end) btcusd['Open'].plot(figsize=(10,6))


it can get everyday's open, close, adj-close, high, low and volume.

Kai-

kaispace30098 avatar Dec 12 '21 18:12 kaispace30098

I went through the example on the documentation and seems that is not working

from pandas_datareader import data

import pandas_datareader.data as web
import pandas as pd
import datetime as dt

df = web.DataReader('GE', 'yahoo', start='2019-09-10', end='2019-10-09')

Here is the error:


RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/GE/history?period1=1568084400&period2=1570676399&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>'

Try a bit differently:

import pandas_datareader as dtr
from datetime import datetime

initial_portfolio=['AAPL', 'MA', 'F', 'MSFT', '^GSPC']
startdate = datetime(2010,1,1)
enddate=datetime(2021,12,3)

stock_data=dtr.yahoo.daily.YahooDailyReader(initial_portfolio,start=startdate,end=enddate).read()

This way you pass start and end data as a date time object. It is working perfectly fine here.

derekmizak avatar Dec 13 '21 20:12 derekmizak

@kaispace30098 That I knew it works.

ghost avatar Dec 13 '21 21:12 ghost

I went through the example on the documentation and seems that is not working

from pandas_datareader import data

import pandas_datareader.data as web
import pandas as pd
import datetime as dt

df = web.DataReader('GE', 'yahoo', start='2019-09-10', end='2019-10-09')

Here is the error:


RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/GE/history?period1=1568084400&period2=1570676399&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>'

Try a bit differently:

import pandas_datareader as dtr
from datetime import datetime

initial_portfolio=['AAPL', 'MA', 'F', 'MSFT', '^GSPC']
startdate = datetime(2010,1,1)
enddate=datetime(2021,12,3)

stock_data=dtr.yahoo.daily.YahooDailyReader(initial_portfolio,start=startdate,end=enddate).read()

This way you pass start and end data as a date time object. It is working perfectly fine here.

It still doesn't work, same error Unable to read URL: https://finance.yahoo.com/quote/AAPL/history?period1=1445054400&period2=1639972799&interval=1d&frequency=1d&filter=history

mSounak avatar Dec 19 '21 18:12 mSounak

Both options worked to me with datetime.date(2021,12,3) as params, after reinstalling the package :)

phnv avatar Dec 29 '21 13:12 phnv

For the original issue where the message was "...Our engineers are working quickly to resolve the issue...", is caused by the Yahoo servers attempting to restrict non standard Use-Agent Strings from the browser. I was getting this error when I attempted to directly pull data from Yahoo using the Python request library. To solve it, I just had to set the the User-Agent string header value. My guess is that the version you are using was not setting that header value. A description of this fix (again from a direct http request methodology) can be found here: 404 Error Yahoo Finance

I'm having a different issue with the YahooDailyReader which I will post in a separate thread.

nmaiorana avatar Mar 26 '22 17:03 nmaiorana