Marco Islas Blog

Python MySQldb little trick

if you are using Python and MySQLdb you may find that using special chars like ñ or ó break the program raising an DecodeError because character xxx is not in the range...
MySQLdb has a way to set the charset for the connection but it is useless if you are using MySQL prior to 4.1. If you are having problems with this, then try doing this:
import MySQLdb
import sys
reload(sys)
sys.setdefaultencoding('latin-1')
 
Replace "latin-1" with your desired encoding and try it.
blog comments powered by Disqus
Comment XML feeds: RSS | Atom
twitter logo