Warning: filemtime() [function.filemtime]: stat failed for 71ba5704c07aec55402cb7d674cb5783 in /home/nomadjourney/www/nomadjourney_com/index.php on line 8

Warning: curl_exec() has been disabled for security reasons in /home/nomadjourney/www/nomadjourney_com/index.php on line 8

Warning: curl_exec() has been disabled for security reasons in /home/nomadjourney/www/nomadjourney_com/index.php on line 8

Warning: Cannot modify header information - headers already sent by (output started at /home/nomadjourney/www/nomadjourney_com/index.php:8) in /home/nomadjourney/www/nomadjourney_com/index.php on line 8
Suppressing MySQL/MySQLdb warning messages from Python | Nomad Journey
Skip to content
Apr 19 / Nizam Sayeed

Suppressing MySQL/MySQLdb warning messages from Python

Here is a quick three line snippet that will suppress all of those annoying warning messages from MySQL when using MySQLdb:

from warnings import filterwarnings
import MySQLdb as Database
filterwarnings('ignore', category = Database.Warning)

To re-enable the warnings later on:

from warnings import resetwarnings
resetwarnings()

More about the warnings Python standard library:
http://docs.python.org/library/warnings.html

4 Comments

  1. Drew / Aug 25 2010

    Thanks.That was useful. Was tired of seeing
    “Statement is not safe to log…” filling up my logs.

  2. Joel Madigan / Nov 10 2010

    Very cool! I had no idea that module even existed. Thanks!

  3. online zeitung / Mar 2 2011

    great thx.

    can you help with IOError: failed to write data
    seems to be from mod_wsgi (pid=20083): Exception occurred processing WSGI script ‘/var/www/www.ngo-online.de/web/django.wsgi’

  4. Melodic Method / Mar 23 2011

    That is excellent! You rock.

Comments are closed.