Trapping MySQLdb warnings
Tim Johnson
tim at johnsons-web.com
Thu Jun 16 15:41:39 EDT 2011
* srinivas hn <hnsri49 at 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
More information about the Python-list
mailing list