我正在尝试使用python3从Google财经下载股票数据(请参阅下面的代码)。 我收到编码错误(请参阅下文)。 因为我一周以来一直在使用python,所以我很感激在调试这个方面有所帮助。我已阅读有关此错误的类似帖子,但遗憾的是我无法使用答案(使用不同的代码/库/方案......)
[错误]
>>> stock_prices = DataReader(ticker, data_source, start, end)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/pandas_datareader/data.py", line
137, in DataReader
session=session).read()
File "/usr/local/lib/python3.6/site-packages/pandas_datareader/base.py", line
181, in read
params=self._get_params(self.symbols))
File "/usr/local/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 "/usr/local/lib/python3.6/site-packages/pandas_datareader/base.py", line
98, in _read_url_as_StringIO
out.write(bytes_to_str(text))
File "/usr/local/lib/python3.6/site-packages/pandas/compat/__init__.py", line
74, in bytes_to_str
return b.decode(encoding or 'utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 18176:
invalid start byte
[代码]:
from pandas_datareader import DataReader
from datetime import date
start = date(2016,1,1)
end = date(2016,12,31)
ticker = 'AAPL'
data_source = 'google'
stock_prices = DataReader(ticker, data_source, start, end)