Trapping MySQLdb warnings

Tim Johnson tim at johnsons-web.com
Thu Jun 16 15:01:06 EDT 2011


* Terry Reedy <tjreedy at udel.edu> [110616 10:50]:
> On 6/16/2011 11:55 AM, Tim Johnson wrote:
> >* Tim Johnson<tim at johnsons-web.com>  [110615 18:53]:
> >>* geremy condra<debatem1 at gmail.com>  [110615 18:03]:
> >>>On Wed, Jun 15, 2011 at 6:58 PM, Tim Johnson<tim at 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?
 The warnings are sent directly to stdout. No way that I know of to
 find out what classes they are..
> >>>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.
 Thanks for that.
> 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.
  OK. I'll stack 'em up and see what happens. Must look at docs
  first.
  thanks again
-- 
Tim 
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com



More information about the Python-list mailing list