[Tutor] Debug help

Jim jf_byrnes at comcast.net
Sun Jul 19 16:25:55 EDT 2020


Mint 18.3 - Python 3.6

I wrote a script that uses the yfinance, oosheet and pandas modules to 
get closing stock prices from Yahoo Finance to  put in a Libreoffice 
spreadsheet to use in a stock trading simulation. I usually run the 
script on a Sunday to get each days closing prices and calculate the 
stocks value in the porfilio for the previous week. The script works 
fine on Mon to Thurs but gives the following error when I try to get 
Fridays prices. If I run the script on the following Monday it works 
without error.

(env36) jfb at jims-mint18 ~ $ /home/jfb/EVs/env36/bin/python3 
/home/jfb/Dev/Python/LO_update_stk_history_yf_dev.py
Traceback (most recent call last):
   File "/home/jfb/Dev/Python/LO_update_stk_history_yf_dev.py", line 
128, in <module>
     update_from_web()
   File "/home/jfb/Dev/Python/LO_update_stk_history_yf_dev.py", line 
102, in update_from_web
     S().value = stk
   File 
"/home/jfb/EVs/env36/lib/python3.6/site-packages/oosheet/__init__.py", 
line 438, in value
     cell.setValue(value)
uno.RuntimeException: Couldn't convert Date
2020-07-17    134858.5 <<Note: the date is the date I input, the num >>
2020-07-17    134858.5 << is the value of the 1st stk in the list>>
Name: Close, dtype: float64 to a UNO type; caught exception: <class 
'AttributeError'>: 'Series' object has no attribute 'getTypes', 
traceback follows
 
/home/jfb/EVs/env36/lib/python3.6/site-packages/pandas/core/generic.py:5274 
in function __getattr__() [return object.__getattribute__(self, name)]

I guess something internal at Yahoo Finance is causing the problem. I 
found an issue that looks similar to mine on the yFinance github page 
and added to it including a small test program to demonstrate the 
problem but never heard back.

Here is the part of the code that generates the error, the remainder of 
the script just manipulates the spreadsheet.

     for stock in stocks:
         # ~ count = 0
         # ~ while count < total_num_of_stocks:
         # ~ while count < 33:
         while True:
             # ~ count = count + 1
             try:
                 # ~ print('Day = ' + day)
                 ticker = yf.Ticker(stock)
                 # ~ print('Ticker = ' + ticker)
                 hist = ticker.history(start=day)
                 # ~ print('History = ' + hist)
                 close_price = hist.loc[day]['Close']
                 # ~ print('Close = ' + close_price)
                 closing_prices.append(close_price)

             except:
                 print ('yfinance JSONDecodeError DAILY, retyring')
                 # ~ print ('ticker: ' + hist)
                 continue
             break

     # Get stock values by multiplying the list elements by number of shares
     # using zip()
     value = [num_shares * stk for num_shares, stk in zip(shares, 
closing_prices)]

     # Put date in cell then go down one row
     S(cell_loc).string = day
     S().dispatch('GoDown')

     # Fill column for MY100000 with stock values using the number of 
stocks in MY100000
     for stk in value[:total_num_MY100000]:
         S().value = stk # Line 102
         S().dispatch('GoDown')

If I run the script with the print lines outside the except commented 
out it will print the date in the spreadsheet, go down 1 cell and throw 
the error and end. If I uncomment any of the print lines it seems to go 
into a endless loop printing out the exception error msg.

I wonder if anyone has an idea of how to figure out what Yahoo Finance 
is doing to cause a problem and I am curious as to why uncommenting a 
print seems to cause an endless loop.

Thanks,  Jim






More information about the Tutor mailing list