Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'wed,': 0.03; 'warnings': 0.05; 'python': 0.08; 'done?': 0.09; 'linux.': 0.09; 'pm,': 0.10; 'wrote:': 0.14; 'cursor': 0.16; 'case.': 0.16; 'cc:addr:python- list': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'object': 0.26; 'tried': 0.27; 'message-id:@mail.gmail.com': 0.28; 'skip:_ 20': 0.28; 'cc:addr:python.org': 0.30; 'url:library': 0.31; 'received:74.125.83.174': 0.35; 'received:mail- pv0-f174.google.com': 0.35; 'else': 0.35; 'using': 0.35; '8bit%:5': 0.36; 'created': 0.36; 'log': 0.36; 'connection': 0.37; 'received:google.com': 0.37; 'url:docs': 0.37; 'url:python': 0.38; 'received:74.125': 0.38; 'url:org': 0.38; 'but': 0.38; 'implemented': 0.38; 'subject:: ': 0.38; 'skip:s 20': 0.39; 'user': 0.39; 'johnson': 0.39; 'printed': 0.39; 'getting': 0.40; 'relevant': 0.69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=9I/895Ikmu1HsaFvhKLs6b6To+IwLocUDygOvE8Cf+Q=; b=h0k+f9Hxzf4jnQGsLi688YP9UZk9o1PrTNNXZyOm14XIPa0F70rO8p0Q44OK6Sz/6J ubwbvV6CulLfhuuivHg98Jvv8Z9ddgMDmm6S5p4GLyVUYYUIGrHCNh9AJgWy5X3rqsJs bcQe4ACIfRGkEC19GJkPza9tpf0Bj3Ju0DmF0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=lTdQCC7/wMttys1Kcjhfy2uCiNs58R/Gz4wmch9klUbCI0Of1e7XBVnwV0+rcLbJdm ccWrIB2UqyXpOpwyGqLlDuwTH97hJG0dmDsgp+chL1xe3QJB0BWhX33XapbLuo1chahE r+queMXIfE1bMtCOmzSgsm8o+igdAcZMwsCQ8= MIME-Version: 1.0 In-Reply-To: <20110616015837.GA1885@johnsons-web.com> References: <20110616015837.GA1885@johnsons-web.com> Date: Wed, 15 Jun 2011 19:03:11 -0700 Subject: Re: Trapping MySQLdb warnings From: geremy condra To: Tim Johnson Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python ML X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308189796 news.xs4all.nl 49042 [::ffff:82.94.164.166]:50621 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7721 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 in this case. > > My cursor is created with the relevant following code: > > ## connection object > self.__conn =3D MySQLdb.connect(db =3D self.__db, > =A0host =3D self.__host, user =3D self.__user, > =A0passwd =3D self.__passwd) > > ## cursor object > self.__rdb =3D self.__conn.cursor() > ## And implemented as : > try : > =A0 =A0self.__rdb.execute(S) > except _mysql_exceptions.Warning,e: > =A0 =A0raise e ## replace with log(e) > > What else needs to be done? Have you tried http://docs.python.org/library/warnings.html#temporarily-sup= pressing-warnings ? Geremy Condra