Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python error while using MysqlDb - sets module is deprecated

Tags:

python

mysql

I'm currently getting the warning every time I run a Python script that uses MySQLdb:

/var/lib/python-support/python2.6/MySQLdb/__init__.py:34:
DeprecationWarning: the sets module is deprecated
  from sets import ImmutableSet

I'd rather not mess with their lib if possible. I'm on Ubuntu server. Anyone know an easy way to fix that warning message?

Thanks

UPDATE: Fixed it based on the suggestions below and this link: https://bugzilla.redhat.com/show_bug.cgi?id=505611

import warnings
warnings.filterwarnings('ignore', '.*the sets module is deprecated.*',
                        DeprecationWarning, 'MySQLdb')
import MySQLdb
like image 682
James Avatar asked Feb 11 '10 23:02

James


2 Answers

Do this before the mysql module is imported

import warnings
warnings.filterwarnings(action="ignore", message='the sets module is deprecated')
import sets
like image 82
John La Rooy Avatar answered Oct 21 '22 16:10

John La Rooy


You can ignore the warning using the warnings module, or the -W argument to Python. Don't ignore all DeprecationWarnings, though, just the ones from MySQLdb :)

like image 22
Thomas Wouters Avatar answered Oct 21 '22 16:10

Thomas Wouters