Reputation: 11
import pandas as pd
import pandas_datareader as web
spy_etf = web.DataReader('SPY','google')
spy_etf.info()
#ERROR
/Users/mac/anaconda3/envs/pyfinance/bin/python /Users/mac/Desktop/M_BOT_AND_TOOLS/Anaconda/PYTHON/_root_exercises/udemy_class_python_for_finance/jobs/Test/test_1.py
Traceback (most recent call last):
File "/Users/mac/Desktop/M_BOT_AND_TOOLS/Anaconda/PYTHON/_root_exercises/udemy_class_python_for_finance/jobs/Test/test_1.py", line 4, in <module>
spy_etf = web.DataReader('SPY','google')
File "/Users/mac/anaconda3/envs/pyfinance/lib/python3.6/site-packages/pandas_datareader/data.py", line 137, in DataReader
session=session).read()
File "/Users/mac/anaconda3/envs/pyfinance/lib/python3.6/site-packages/pandas_datareader/base.py", line 181, in read
params=self._get_params(self.symbols))
File "/Users/mac/anaconda3/envs/pyfinance/lib/python3.6/site-packages/pandas_datareader/base.py", line 79, in _read_one_data
out = self._read_url_as_StringIO(url, params=params)
File "/Users/mac/anaconda3/envs/pyfinance/lib/python3.6/site-packages/pandas_datareader/base.py", line 90, in _read_url_as_StringIO
response = self._get_response(url, params=params)
File "/Users/mac/anaconda3/envs/pyfinance/lib/python3.6/site-packages/pandas_datareader/base.py", line 139, in _get_response
raise RemoteDataError('Unable to read URL: {0}'.format(url))
pandas_datareader._utils.RemoteDataError: Unable to read URL: http://www.google.com/finance/historical?q=SPY&startdate=Jan+01%2C+2010&enddate=Aug+17%2C+2018&output=csv
Process finished with exit code 1
Not being able to acess google financial historial data
Upvotes: 0
Views: 955
Reputation: 20561
The problem is not with your code, but google's support of your query.
If you were to manually GET
the generated url:
import requests
requests.get('http://www.google.com/finance/historical?q=SPY&startdate=Jan+01%2C+2010&enddate=Aug+17%2C+2018&output=csv')
# results in <Response [403]>
You will notice the url results in a 403 response, meaning access to the url is forbidden. As a result you get the pandas_datareader._utils.RemoteDataError: Unable to read URL
Upvotes: 1