My first post! (congrats to me Sorry if this is a newbie question, but I have not found a good answer across all of the many sites I have searched.
I am using a Try / Except block – like the one below – to catch the Overflow error that occurs due to an out-of-boundary date. The boundary dates can vary widely (depending on when the company data stream started) so I am trying to use Try / Except to find the boundary and code around it.
If you run the code below with the two dates (‘1969-12-31’ = out-of-bounds date and ‘1970-1-1’ = in-bounds date), you’ll see that the yfinance.download method halts execution with the bad date rather than passing through to the “except” clause. I have tried this with many options for the except line (i.e. bare except, except OverflowError, except ValueError, etc.) Nothing seems to work.
FYI - I am using Python 3.8 with Spyder IDE 4.1.5 Any help would be very much appreciated!
import yfinance as yf ticker='CVX' startdate='1970-01-01' # Also run with this -> startdate='1969-12-31' enddate='2021-12-31' try: hist = yf.download(ticker, start=startdate, end=enddate, progress=False) except OverflowError: pass