yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

some errors are not `raise`d, but rather `print`ed

Open hamid-vakilzadeh opened this issue 2 years ago • 4 comments

  • Simple code that reproduces your problem when requesting a non-existing ticker symbol, the history method does not handle it as an error, but just a print output. Therefore, since no error is raised, error handling using try and except is not possible. For example:
import yfinance as yf

# trying a ticker that does not exist
ticker = yf.Ticker('T1XN')
try:
    ticker.history(period='max')
except:
    print("not found")
  • The error message
Got error from yahoo api for ticker T1XN, Error: {'code': 'Not Found', 'description': 'No data found, symbol may be delisted'}
- T1XN: No data found for this date range, symbol may be delisted

The error message is not actually an error message! right now the error is a print output rather than raise

hamid-vakilzadeh avatar Nov 11 '22 19:11 hamid-vakilzadeh

yfinance has always handled errors like this, I don't know why that decision was made because before me. But I've added a new argument raise_errors to 0.2 to actually throw Exceptions.

ValueRaider avatar Nov 11 '22 19:11 ValueRaider

@ValueRaider okay thank you for quick response! I guess this issues can be closed now!

hamid-vakilzadeh avatar Nov 11 '22 20:11 hamid-vakilzadeh

For me, raise_errors has no effect here at all. Errors are just printed, not great when using tqdm to show progress.

misantroop avatar Dec 20 '22 09:12 misantroop

@misantroop What ticker prints an error? Any ticker so we can reproduce.

ValueRaider avatar Dec 20 '22 16:12 ValueRaider