MySQL special chars lost when queried in Python. (But works with Django.) -


i have mysql database utf8 encoded. contains row value "sauté". note accent on e.

when select data using django application correctly detects é. however, when execute python program information (the special e) seems lost.

i've tried various combinations of encode , decode , "from future import unicode_literals" , putting "u" in front of sauté string , putting u in front of query string. no luck. how can info correctly out of database (with python) , test it?

# connection when excute .py:  (django usual in settings.py) cursor = mysqldb.connect(host='<xxx>',user="<xxx>", passwd="<xxx>", db="<xxx>",           unix_socket = 'path/mysql.sock'           ).cursor()   # same code in django , python execution:  cursor.execute(select line my_table id = 27) results = cursor.fetchall() r in results:     line = r[0]     if re.search("sauté", line):         do_something() # should here, django 

thanks jd vangsness (in comments) answer.

i needed add charset='utf8' connection parameters.

cursor = mysqldb.connect(host='<xxx>',user="<xxx>", charset='utf8', passwd="<xxx>", db="<xxx>", unix_socket = 'path/mysql.sock').cursor()  

and needed make comparison string unicode:

u"sauté" 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -