[Tutor] Accessing Yahoo with Python?

Jim Byrnes jf_byrnes at comcast.net
Sat Oct 8 18:29:45 EDT 2016


I realize that my question is not about the standard library. The only 
reason I am asking here is, if I remember correctly, a regular 
contributor, Danny Yoo, works at Yahoo. I am hoping he, or someone else 
here can help me understand what is happening.

I am writing a program using the yahoo_finance module. Over the past 
week I have been testing and refining it. At first the only errors I was 
seeing were mine.  Lately I have been a lot of these errors.

Traceback (most recent call last):
   File 
"/usr/local/lib/python3.4/dist-packages/yahoo_finance/__init__.py", line 
120, in _request
     _, results = response['query']['results'].popitem()
KeyError: 'query'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   File "/home/jfb/MyProgs/StockHistory/stock_history_oop.py", line 75, 
in <module>
     Stocks().run()
   File "/home/jfb/MyProgs/StockHistory/stock_history_oop.py", line 38, 
in run
     self.get_stock_info()
   File "/home/jfb/MyProgs/StockHistory/stock_history_oop.py", line 53, 
in get_stock_info
     yahoo = Share(stk)
   File 
"/usr/local/lib/python3.4/dist-packages/yahoo_finance/__init__.py", line 
178, in __init__
     self.refresh()
   File 
"/usr/local/lib/python3.4/dist-packages/yahoo_finance/__init__.py", line 
142, in refresh
     self.data_set = self._fetch()
   File 
"/usr/local/lib/python3.4/dist-packages/yahoo_finance/__init__.py", line 
181, in _fetch
     data = super(Share, self)._fetch()
   File 
"/usr/local/lib/python3.4/dist-packages/yahoo_finance/__init__.py", line 
134, in _fetch
     data = self._request(query)
   File 
"/usr/local/lib/python3.4/dist-packages/yahoo_finance/__init__.py", line 
123, in _request
     raise YQLQueryError(response['error']['description'])
yahoo_finance.YQLQueryError: Query failed with error: "'No definition 
found for Table yahoo.finance.quotes'".

It has gotten to the point where if I run the program 10 times, 9 of 
them will return the above error before I get the data I want. The part 
of my program that retrieves the data from Yahoo has not changed in 
quite a while.

Is it possible that I have exceeded a Yahoo limit on requests from one 
IP address?  Test data I am using gets the historical info on 3 stocks 
over a 3 day period.

Thanks,  Jim



More information about the Tutor mailing list