Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7759

Re: Trapping MySQLdb warnings

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Trapping MySQLdb warnings
Date 2011-06-16 14:47 -0400
References <20110616015837.GA1885@johnsons-web.com> <BANLkTint8YP9W7hUnvYh4nmMo_6h0WPXTA@mail.gmail.com> <20110616023829.GB1885@johnsons-web.com> <20110616155533.GD1885@johnsons-web.com>
Newsgroups comp.lang.python
Message-ID <mailman.29.1308250082.1164.python-list@python.org> (permalink)

Show all headers | View raw


On 6/16/2011 11:55 AM, Tim Johnson wrote:
> * Tim Johnson<tim@johnsons-web.com>  [110615 18:53]:
>> * geremy condra<debatem1@gmail.com>  [110615 18:03]:
>>> On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson<tim@johnsons-web.com>  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.
>> <.....>

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?

>>> Have you tried http://docs.python.org/library/warnings.html#temporarily-suppressing-warnings
>>    Hi Geremy:
>>    I just looked at the docs there. This is a new module (to me), and
>>    I am unsure of the implementation or whether this is what I should
>>    use.
>>    I tried the following :
>> 		try :
>> 			self.__rdb.execute(S)
>> 		except warnings.catch_warnings:

warnings.catch_warnings is a context manager, not an exception.
This is a TypeError in 3.x, which requires that exceptions be instances 
of BaseException. Try
      except warnings.Warning, warn:

Substitute specific MySQLdb warning class, whatever it is, for Warning.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Trapping MySQLdb warnings Terry Reedy <tjreedy@udel.edu> - 2011-06-16 14:47 -0400

csiph-web