以前,我使用Morningstar API获取股票数据;然而,现在我离开美国一个星期了,我不能访问这些数据。
下面是代码片段:
import datetime as dt
from dateutil.relativedelta
import relativedelta
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader.data as web
import csv
from mpl_finance
import candlestick_ohlc
import matplotlib.dates as mdates
from matplotlib.dates import DateFormatter, MonthLocator, YearLocator, DayLocator, WeekdayLocator
style.use( 'ggplot' )
end = dt.date.today()
start_48 = end - relativedelta( years=4 )
start_120 = end - relativedelta( years=10 )
ticker = input( 'Ticker: ' ) #should be in Uppercase
ticker = ticker.upper()
df_w = web.DataReader( ticker, 'morningstar', start_48, end )
df_m = web.DataReader( ticker, 'morningstar', start_120, end )
print()
file_name_w = ticker + 'weekly.csv'
file_name_m = ticker + 'monthly.csv'
df_w.to_csv( file_name_w )
df_m.to_csv( file_name_m )
df_w = pd.read_csv( file_name_w, parse_dates=True, index_col=0 )
df_m = pd.read_csv( file_name_m, parse_dates=True, index_col=0 )
这是错误消息:
Ticker: spy
Traceback (most recent call last):
File "/Users/zubairjohal/Documents/OHLC.py", line 24, in <module>
df_w = web.DataReader( ticker, 'morningstar', start_48, end )
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/data.py", line 391, in DataReader
session=session, interval="d").read()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/mstar/daily.py", line 219, in read
df = self._dl_mult_symbols(symbols=symbols)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas_datareader/mstar/daily.py", line 130, in _dl_mult_symbols
resp.status_code, resp.reason))
Exception: Request Error!: 404 : Not Found
这是一个IP问题吗?有没有办法解决这个问题?我知道这个代码很好,因为两天前它运行得非常好。
2条答案
按热度按时间35g0bw711#
我在美国也遇到了同样的问题。datareader服务(晨星)3天前工作,前天停止工作。我相信晨星改变了这里的REST接口,所以除了等待开发人员修复它,我们没有什么可以做的。
g52tjvyc2#
404意味着找不到,假设你没有做任何更改,突然不工作,我会说这是要么API的URL是无法访问的国家(或阻止在该特定的网络)或他们的API已更改(或正在维护中).如果你知道API的URL尝试直接在浏览器与不同的互联网连接.