Re: Trapping MySQLdb warnings

2011-06-16 Thread Tim Johnson
* srinivas hn [110616 11:06]: > Hi Tim, > >import warnings > > with warnings.catch_warnings(): > warnings.simplefilter('error', MySQLdb.Warning) > try: > cursor.execute(insert_query) > conn.commit() > return 'Success' > except MySQLdb.Error, error: > loggi

Re: Trapping MySQLdb warnings

2011-06-16 Thread Tim Johnson
* srinivas hn [110616 11:06]: > Hi Tim, > > Use this method it will sort tour problem. > > def do_query(insert_query): >import warnings > > with warnings.catch_warnings(): > warnings.simplefilter('error', MySQLdb.Warning) > try: > cursor.execute(insert_query) > conn.comm

Re: Trapping MySQLdb warnings

2011-06-16 Thread Terry Reedy
On 6/16/2011 3:01 PM, Tim Johnson wrote: * Terry Reedy [110616 10:50]: The machinery in the warnings module is only for instances of subsclasses of Warning. Are the warnings from MySQLdb properly such objects? If so, what class are they? The warnings are sent directly to stdout. No way t

Re: Trapping MySQLdb warnings

2011-06-16 Thread Tim Johnson
* Terry Reedy [110616 10:50]: <...> > Substitute specific MySQLdb warning class, whatever it is, for Warning. Hmm! Consider the following code: try : self.__rdb.execute(S) raise MySQLdb.Warning('danger, danger Monte Python') ## just for grins except MySQLdb.Warning,e: std.debug("e",e,0,0,

Re: Trapping MySQLdb warnings

2011-06-16 Thread Tim Johnson
* Terry Reedy [110616 10:50]: > On 6/16/2011 11:55 AM, Tim Johnson wrote: > >* Tim Johnson [110615 18:53]: > >>* geremy condra [110615 18:03]: > >>>On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson wrote: > Using Python 2.6.5 on linux. > > When using MySQLdb I am getting warnings printe

Re: Trapping MySQLdb warnings

2011-06-16 Thread srinivas hn
Hi Tim, Use this method it will sort tour problem. def do_query(insert_query): import warnings with warnings.catch_warnings(): warnings.simplefilter('error', MySQLdb.Warning) try: cursor.execute(insert_query) conn.commit() return 'Success' except MySQLdb.Error, e

Re: Trapping MySQLdb warnings

2011-06-16 Thread Terry Reedy
On 6/16/2011 11:55 AM, Tim Johnson wrote: * Tim Johnson [110615 18:53]: * geremy condra [110615 18:03]: On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson wrote: Using Python 2.6.5 on linux. When using MySQLdb I am getting warnings printed to stdout, but I would like to trap, display and log tho

Re: Trapping MySQLdb warnings

2011-06-16 Thread Tim Johnson
* Tim Johnson [110615 18:53]: > * geremy condra [110615 18:03]: > > On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson wrote: > > > Using Python 2.6.5 on linux. > > > > > > When using MySQLdb I am getting warnings printed to stdout, but I would > > > like to trap, display and log those warnings. > <..

Re: Trapping MySQLdb warnings

2011-06-15 Thread Tim Johnson
* geremy condra [110615 18:03]: > On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson wrote: > > Using Python 2.6.5 on linux. > > > > When using MySQLdb I am getting warnings printed to stdout, but I would > > like to trap, display and log those warnings. <.> > Have you tried > http://docs.python.

Re: Trapping MySQLdb warnings

2011-06-15 Thread geremy condra
On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson wrote: > Using Python 2.6.5 on linux. > > When using MySQLdb I am getting warnings printed to stdout, but I would > like to trap, display and log those warnings. > > In the past I have used _mysql_exceptions.Warning, but that approach > is not working i

Trapping MySQLdb warnings

2011-06-15 Thread Tim Johnson
Using Python 2.6.5 on linux. When using MySQLdb I am getting warnings printed to stdout, but I would like to trap, display and log those warnings. In the past I have used _mysql_exceptions.Warning, but that approach is not working in this case. My cursor is created with the relevant following co