user5208585
user5208585

Reputation:

Python 2.7 Yahoo Finance No Definition Found

Hope you are well. I'm Using Python 2.7 and new at it. I'm trying to use yahoo finance API to get information from stocks, here is my code:

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

This code thoug works once out of 4 attempts, the other 3 times gives me this errors:

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

Is there anyway to fix this error so to have the code working 100% of the time? Thanks. Warmest regards

Upvotes: 0

Views: 298

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1121904

This is a server-side error. The query.yahooapis.com service appears to be handled by a cluster of machines, and some of those machines appear to be misconfigured. This could be a temporary problem.

I see the same error when accessing the API directly using curl:

$ 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"}}

Other than retrying in a loop, there is no way to fix this on the Python side:

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'

Upvotes: 1

Related Questions