KAP
KAP

Reputation: 29

Error when loading data using web.DataReader, yahoo finance

I try to load data using web.DataReader but I always get the error "RemoteDataError: Unable to read URL: https://finance.yahoo.com/quote/FB/history?period1=1325390400&period2=1577937599&interval=1d&frequency=1d&filter=history".

I already used the following package updates and my code worked fine yesterday. However today I still get the same error as before (i.e., unable to read URL).

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

PS: I use Google Colab

Here is the full beginning of my code (including the error):

!pib install numpy
!pib install matplotlib
!pib install pandas
!pip install --upgrade pandas
!pip install --upgrade pandas-datareader

 # Importing packages
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import pandas_datareader as web
import datetime as dt
from sklearn.preprocessing import MinMaxScaler #package used in order to scale the data
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Dropout, LSTM
# Load Data 
company = 'FB' #picking the company we want to study

start=dt.datetime(2012,1,1) # picking the dataframe we are interested in 
end=dt.datetime(2020,1,1)
data = web.DataReader(company, 'yahoo',start,end)

RemoteDataError Traceback (most recent call last) in () ----> 1 data = web.DataReader(company, 'yahoo',start,end)

4 frames /usr/local/lib/python3.7/dist-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/FB/history?period1=1325390400&period2=1577937599&interval=1d&frequency=1d&filter=history Response Text: b'\n \n \n \n Yahoo\n \n \n \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 \n \n document.write('&test=\'+encodeURIComponent(\'%\')+\'" width="0px" height="0px"/>');var beacon = new Image();beacon.src="//bcn.fp.yahoo.com/p?s=1197757129&t="+ne...

Upvotes: 0

Views: 2282

Answers (1)

KAP
KAP

Reputation: 29

If anyone faces the same issue as mine, I just found out how to solve it!

Adapt this piece of code in your notebook:

start=dt.datetime(2010,1,1)
end=dt.datetime(2017,1,1)
df = yf.download(tickers=['^GSPC'], start=start, end=end)

Upvotes: 3

Related Questions