having problem to store unicode to database. for your information 你 = you..
>> a='你'
>>a <\br>
'\xc4\xe3'
the problem is
# -*- coding: utf-8 -*-
import MySQLdb
db = MySQLdb.Connect(host="127.0.0.1", port=3306, user="root", passwd="root",db="mydata", charset="utf8", use_unicode=True)
cursor = db.cursor()
insert = "insert into testing (english,chinese,frequency) values(%s,%s,1) on duplicate KEY UPDATE frequency=frequency+1;"
a='你'
data=('you',a)
try:
cursor.execute(insert,data)
except:
print "error"
db.commit()
which return me an error, but when i change to this
data=('you','你')
it works....
can anyone help me?? i need to use "data=('you',a)" because later i will import chinese chracter file
how do i make it to u'\xc4\xe3\xba\xc3' – khheng Feb 21 '13 at 18:59
error message UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128) – khheng Feb 21 '13 at 19:45