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


Groups > comp.lang.python > #7765 > unrolled thread

Re: Trapping MySQLdb warnings

Started byTim Johnson <tim@johnsons-web.com>
First post2011-06-16 11:41 -0800
Last post2011-06-16 11:41 -0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Trapping MySQLdb warnings Tim Johnson <tim@johnsons-web.com> - 2011-06-16 11:41 -0800

#7765 — Re: Trapping MySQLdb warnings

FromTim Johnson <tim@johnsons-web.com>
Date2011-06-16 11:41 -0800
SubjectRe: Trapping MySQLdb warnings
Message-ID<mailman.39.1308253297.1164.python-list@python.org>
* srinivas hn <hnsri49@gmail.com> [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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web