无法读取URL pandas_datareader

时间:2018-08-17 18:24:37

标签: python pandas anaconda

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

1 个答案:

答案 0 :(得分:0)

问题不在于您的代码,而是Google对您查询的支持。 如果要手动GET生成的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]>

您会注意到该URL结果显示为403,这意味着禁止访问该URL。结果,您得到了pandas_datareader._utils.RemoteDataError: Unable to read URL

相关问题