Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'warnings': 0.05; 'srinivas': 0.07; 'finally:': 0.09; 'received:64.4': 0.09; 'tim,': 0.09; 'def': 0.12; 'error:': 0.12; '*very*': 0.16; 'conn.close()': 0.16; 'error)': 0.16; 'header:In-Reply-To:1': 0.21; 'code.': 0.22; 'do,': 0.25; 'statement': 0.26; 'thanks': 0.28; 'import': 0.29; 'least': 0.30; 'sort': 0.31; 'to:addr:python-list': 0.33; 'post': 0.33; 'header:User-Agent:1': 0.35; 'try:': 0.35; 'charset:us- ascii': 0.36; 'query': 0.37; 'problem.': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'some': 0.38; 'got': 0.39; 'to:addr:python.org': 0.39; 'hope': 0.60; 'back': 0.63; 'tour': 0.82; 'yeah!': 0.84 Date: Thu, 16 Jun 2011 11:41:39 -0800 From: Tim Johnson To: python-list@python.org Subject: Re: Trapping MySQLdb warnings References: <20110616015837.GA1885@johnsons-web.com> <20110616023829.GB1885@johnsons-web.com> <20110616155533.GD1885@johnsons-web.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: AkWebsoft User-Agent: Mutt/1.5.20 (2009-06-14) 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: 37 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308253297 news.xs4all.nl 49041 [::ffff:82.94.164.166]:32932 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7765 * 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.commit() > return 'Success' > except MySQLdb.Error, error: > logging.error("Error in insertion %s query is ", error) > return 'Failure' > finally: > conn.close() > > > try: > xyz = do_query(insert_query) > except MySQLdb.Warning, warning: > logging.warning(warning) > > > you need to use the with statement and then you need to catch the warnings > hope it helps Yeah! Got some tweaking to do, but will post back again on working code. At least I am now raising errors. thanks *very* much. -- Tim tim at johnsons-web dot com or akwebsoft dot com http://www.akwebsoft.com