I would like to catch and log MySQL warnings in Python. For example, MySQL issues a warning to standard error if you submit
'DROP DATABASE IF EXISTS database_of_armaments'
'DRP DATABASE database_of_armaments'
cursor.execute('DROP DATABASE IF EXISTS database_of_armaments')
except: <<WHAT DO I PUT HERE?>>
print 'There was a MySQL warning.'
<<AND what goes here if I want to get and manipulate information about the warning?>>
Follow these steps.
Run it with
except Exception, e: print repr(e).
See what exception you get.
Exception to the exception you actually got.
Also, remember that the exception, e, is an object. You can print
e.__class__.__name__, etc.to see what attributes it has.
Also, you can do this interactively at the
>>> prompt in Python. You can then manipulate the object directly -- no guessing.