python - trapping a MySql warning -
in python script trap "data truncated column 'xxx'" warning durnig query using mysql.
i saw posts suggesting code below, doesn' work.
do know if specific module must imported or if option/flag should called before using code?
thanks all
afeg
import mysqldb try: cursor.execute(some_statement) # code steps here: no warning trapped # code below except mysqldb.warning, e: # handle warnings, if cursor you're using raises them except warning, e: # handle warnings, if cursor you're using raises them
warnings that: warnings. reported (usually) stderr, nothing else done. can't catch them exceptions because aren't being raised.
you can, however, configure do warnings, , turn them off or turn them exceptions, using warnings
module. instance, warnings.filterwarnings('error', category=mysqldb.warning)
turn mysqldb.warning warnings
exceptions (in case caught using try/except) or 'ignore'
not show them @ all. can (and should) have more fine-grained filters category.
Comments
Post a Comment