Information appears to be coming out of mysqldb incorrectly, python django

In latin-1 database I have " \222\222\223\225

" when I try to pull this field from django models I get back u'\u2019\u2019\u201c\u2022'


from django.db import connection                                                                                                                                                                                                                                                    
cursor = connection.cursor()                                                                                                                                                                                                                                                        
cursor.execute("SELECT Password from campaignusers WHERE UserID=26")                                                                                                                                                                                                             
row = cursor.fetchone()


So I get into this and I get into

/usr/local/python2.5/lib/python2.5/site-packages/MySQL_python-1.2.2-py2.5-linux-i686.egg/MySQLdb/ fetchone () → (u ' \ u2019 ... 1c \ u2022 ',)

I can't go any further because this is an egg, but it seems that the MySQL python driver is not interpreting the data as latin-1.

Does anyone know what's going on?


source to share

2 answers

A little look at the questions already asked would lead you to problems converting UTF-8 to latin-1 , which was asked and answered yesterday.

By the way, I couldn't remember the exact title, so I just searched google on django + '\ 222 \ 222 \ 223 \ 225' and found it. Remember kids, Google is your friend (tm).



Django uses UTF-8 unless you define DEFAULT_CHARSET as something else. Keep in mind that in order to define a different encoding you will need to encode all your templates in that encoding, and that encoding will appear here, there, for example, in email encoding, in sitemaps and feeds, etc. So IMO, the best you can do is go to UTF-8, this will save you a lot of headaches with Django (internally all unicode, problems are at the boundaries of your application, like templates and input).



All Articles