0
votes

Error loading data for SPY from google finance using the Pandas web datareader:

import pandas_datareader.data as web dfSPY = web.DataReader('SPY', 'google', start_date, end_date)

File "/home/user/Projects/pmb/dataaccess.py", line 63, in import_data dfSPY = web.DataReader('SPY', 'google', start_date, end_date) File "/home/user/anaconda3/envs/quant35/lib/python3.5/site-packages/pandas_datareader-0.5.0-py3.5.egg/pandas_datareader/data.py", line 137, in DataReader session=session).read() File "/home/user/anaconda3/envs/quant35/lib/python3.5/site-packages/pandas_datareader-0.5.0-py3.5.egg/pandas_datareader/base.py", line 181, in read params=self._get_params(self.symbols)) File "/home/user/anaconda3/envs/quant35/lib/python3.5/site-packages/pandas_datareader-0.5.0-py3.5.egg/pandas_datareader/base.py", line 79, in _read_one_data out = self._read_url_as_StringIO(url, params=params) File "/home/user/anaconda3/envs/quant35/lib/python3.5/site-packages/pandas_datareader-0.5.0-py3.5.egg/pandas_datareader/base.py", line 98, in _read_url_as_StringIO out.write(bytes_to_str(text)) File "/home/user/anaconda3/envs/quant35/lib/python3.5/site-packages/pandas/compat/init.py", line 73, in bytes_to_str return b.decode(encoding or 'utf-8')

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 34539: invalid continuation byte

1

1 Answers

1
votes

This is an open issue in you can see it here: https://github.com/pydata/pandas-datareader/issues/424

This is how i solved based on the comments from github:

Check if GoogleDailyReader.url() in pandas_datareader/google/daily.py returns 'http://www.google.com/finance/historical'. If so, change it to 'http://finance.google.com/finance/historical'. (www -> finance) The return value of GoogleDailyReader.url() was 'http://www.google.com/finance/historical' when I downloaded pandas-datareader in PyCharm yesterday. I don't know why.

Test it with:

import pandas_datareader as pdr
c = pdr.google.daily.GoogleDailyReader()

c.url
# http://www.google.com/finance/historical'

pdr.__version__
# '0.5.0'