How to suppress yfinance exception from getting printed in Spyder IDE

38 views Asked by At
import yfinance as yf,pandas as pd, numpy as np, os, sys
from datetime import datetime, timedelta, timezone
from pandas_datareader import data as pdr
from pandas_datareader._utils import RemoteDataError

# Call yf.pdr_override() to override pandas_datareader's default behavior with yfinance.
yf.pdr_override()

data_incremental = pd.DataFrame()
stock='^NSEBANK'

try:
   data_incremental = pdr.get_data_yahoo(stock, start=start_time, interval="1m")
except:
   pass

I am using above code to be called in a while loop with 20 seconds of sleep time in-between two calls.

Seems like above code should hide all exceptions thrown by yfinance but I still get below error which I want to suppress as it is cluttering the spyder console

Error Message:

ERROR:yfinance:
1 Failed download:
ERROR:yfinance:['^NSEBANK']: Exception('%ticker%: No price data found, symbol may be delisted (1m 2024-01-20 15:31:00+05:30 -> 2024-01-20 19:14:20+05:30)')  
0

There are 0 answers