This post is the same with my question in MySQL in Python: UnicodeEncodeError: 'ascii' this is just to clear things up.
I am trying to save a string to a MySQL database but I get an error:
File ".smart.py", line 51, in (number, text, 'smart', 'u')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 25: ordinal not in range(128)
and the string is saved at m['Text']
Lala*=#&%@<>_?!:;-'"/()¥¡¿
Here is a snippet to the code
risk = m['Text']
msg = risk.encode('utf8')
text = db.escape_string(msg)
sql = "INSERT INTO posts(nmbr, \
msg, tel, sts) \
VALUES ('%s', '%s', '%s', '%s')" % \
(number, text, 'smart', 'u')
If i try to comment out the SQL query and put print text it would print out Lala*=#&%@<>_?!:;-'"/()¥¡¿
The error is only encountered when the SQL is being processed.
MySQL encoding is set to utf8_unicode_ci. (or should i change this?)
Thanks.