Take the 2-minute tour ×

I'm changing a lot in an app, db schema among others. Im trying to create a dump from the old database in the new database schema ie.

cursor.execute("SELECT * FROM recv WHERE user="+str(oldID))
for i in cursor:
    list = [
    inbQuery += "INSERT INTO `inbox` (`id`, `phoneNumber`, `text`, `date`, `csca`, `user_id`, `visible`, `seen`)" \
                " VALUES (NULL, '%s', '%s', '%s', '%s', %s, '%s', %s);\n" % tuple(list)

However I've come across this error:


UnicodeEncodeError: 'ascii' codec can't encode character u'\u015b' in position 6: ordinal not in range(128)

How do I overcome this? I realize I could just use cursor.execute() to do the escaping, however I do not want to run the queries, only create them as strings.

share|improve this question
You could UTF-8 encode the string: conn.escape_string(i[2].encode('utf-8')) –  xbonez Mar 22 '13 at 14:26
@xbonez Worked. (conn.escape_string(i[2].encode('utf-8')).decode('utf-8'), for the curious) Feel free to post this as answer so I can accept it –  Robus Mar 22 '13 at 14:29
add comment


Your Answer



Browse other questions tagged or ask your own question.