【发布时间】:2017-04-01 18:09:04
【问题描述】:
我正在使用以下代码从 nasdaq 下载的符号列表中读取来自 yahoo Finance 的数据。
pnls = {i:dreader.DataReader(i,'yahoo','1985-01-01','2017-03-30') for i in symbols}
for df_name in pnls:
try:
pnls.get(df_name).to_csv("/Users/Jiong/Documents/data/{}_data.csv".format(df_name), index=True, header=True)
except:
print("error {}".format(df_name))
else:
print("done {}".format(df_name))
猜测某些符号可能无效,雅虎财经抛出 RemoteDataError Exception。
上面的代码应该继续运行,但它仍然在错误处停止。
难道不是要捕获所有异常吗?或者这是运行时错误?
无论如何要让代码忽略它并继续?谢谢。查看下面运行的错误
118 if params is not None and len(params) > 0:
119 url = url + "?" + urlencode(params)
--> 120 raise RemoteDataError('Unable to read URL: {0}'.format(url))
121
122 def _read_lines(self, out):
RemoteDataError: Unable to read URL: http://ichart.finance.yahoo.com/table.csv?c=1985&f=2017&s=MITT%5EA&g=d&ignore=.csv&d=2&e=30&a=0&b=1
【问题讨论】:
标签: python try-catch yahoo-finance except