I have run into the following error when trying to do an INSERT
in Russian:
sql = """SELECT provider FROM main_app_provider WHERE provider LIKE %s"""
cursor.execute(sql, args)
[ print statement ]
SELECT provider FROM main_app_provider WHERE provider LIKE Централ%
...
File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 202, in unicode_literal
return db.literal(u.encode(unicode_literal.charset))
UnicodeEncodeError: 'latin-1' codec can't encode characters
in position 0-6: ordinal not in range(256)
How would I go about fixing this?
MySQLdb defaults to using latin-1, you have to set the character set you want it to use. (See this question: python encoding problem with mysqldb)
I do this when creating a connection, eg
conn=MySQLdb.connect(hostname, username, password, database, charset='utf8')