| Bug #76982 | 'ascii' codec can't decode byte... cursor not handling utf8 string? | ||
|---|---|---|---|
| Submitted: | 8 May 2015 10:05 | Modified: | 17 Jul 2015 9:05 |
| Reporter: | Tomer Paz | Email Updates: | |
| Status: | Not a Bug | Impact on me: | |
| Category: | Connector / Python | Severity: | S5 (Performance) |
| Version: | 2.0.3, 2.0.4 | OS: | Linux (Ubuntu 14.04.1) |
| Assigned to: | CPU Architecture: | Any | |
| Tags: | python mysql-connector utf8 | ||
[8 May 2015 10:56]
Tomer Paz
update: just for other people who might fall into this pitfall, a work-around (or fix if you will) is to first do:
subject.encode('unicode_escaped')
i.e. encode the string as above before pushing it to mysql connector cursor.
[17 Jul 2015 9:05]
Andrii Nikitin
It doesn't look like MySQL Connector issue, so I close this as 'Not a bug'

Description: Error: 'ascii' codec can't decode byte 0xd7 in position 153: ordinal not in range(128). I get this message on utf-8 strings when trying an INSERT INTO query such as in the documented example: statement = ("INSERT INTO {db}.newsletters (name, format, active, archive, subject, textbody, htmlbody, createdate, ownerid) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s);" \ .format(db='mydb')) data = (name, format, 1, 1, subject, '', '', createdate, ownerid) for result in cursor.execute(statement, data, multi=True): ... connector version: 2.0.3 and 2.0.4 the 'subject' value is utf-8. ? How to repeat: see the example code in description Suggested fix: MySQLdb has escape_string() function that according to documentation at least knows how to handle such strings...