Python Forum

Full Version: pymysql won't handle some diacritic characters
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm using the pymysql library in an AWS Lambda function in order to insert records into a MySQL database table. One of the table's columns is intended to hold Welsh language text, which works well for most characters, including diacritics. However, the circumflexed characters w and y are not correctly preserved when written to the database via pymysql - instead they are represented by a question mark when subsequently viewed via a SELECT statement.

My pymysql connection object is set as follows:
conn = pymysql.connect(host=host_name, user=user_name, password=password, db=db_name, charset='utf8')

For instance, when passing the following string via pymysql, every character, apart from the circumflexed w and circumflexed y is correctly written to the database, showing that the database can store UTF-8 characters fine:
"Some Welsh diacritics: â, ê, î, ô, û, ŵ, ŷ à, è, ì, À, È. End of diacritics."

Note that when INSERTing the string directly using MySQLWorkbench, the circumflexed characters w and y are correctly written to the database, so the problem would seem to lie with pymysql. I don't understand why, for instance, pymysql handles circumflexed u fine but not circumflexed w.

Any ideas on how to resolve this issue would be appreciated.