Python 2.7 雅虎财经未找到定义

Python 2.7 Yahoo Finance No Definition Found

希望你一切都好。我正在使用 Python 2.7 和新版本。我正在尝试使用 yahoo finance API 从股票中获取信息,这是我的代码:

from yahoo_finance import Share
yahoo = Share('YHOO')
print yahoo.get_historical('2014-04-25', '2014-04-29') 

此代码 though 在 4 次尝试中成功了一次,其他 3 次给我这个错误:

YQL Query error: Query failed with error: No Definition found for Table yahoo.finance.quote 

有没有办法修复这个错误,让代码 100% 正常工作? 谢谢。 最诚挚的问候

这是一个服务器端错误query.yahooapis.com 服务似乎由一组机器处理,其中一些机器似乎配置错​​误。这可能是暂时的问题。

我在直接使用 curl 访问 API 时看到同样的错误:

$ curl "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20%3D%20%22YHOO%22&format=json&env=store%3a//datatables.org/alltableswithkeys"
{"error":{"lang":"en-US","description":"No definition found for Table yahoo.finance.quote"}}

除了在循环中重试,Python 方面没有办法解决这个问题:

data = None
for i in range(10):  # retry 10 times
    try:
        yahoo = Share('YHOO')
        data = yahoo.get_historical('2014-04-25', '2014-04-29')
        break
    except yahoo_finance.YQLQueryError:
        continue
if data is None:
    print 'Failed to retrieve data from the Yahoo service, try again later'