1

In MySQL I have a field with the value: "Rœschwoog"

The charset of the MySQL table is UTF-8. When I retrieve that value from Python 3.4, I save it into a dict. When I print that dict, I realize that the value is not "Rœschwoog" but "R\x9cschwoog" instead. Why is this happening? How can I get the real value?

I create the MySQL connection with:

conn = pymysql.connect(host='127.0.0.1', user='xxx', passwd="yyy", db='mydb')
4
  • "R\x9cschwoog" is Python's representation of the string Rœschwoog encoded in the windows-1252 encoding. Can you please add the relevant parts of your code (a simplified testcase) to your question? Particularly, what connection parameters do you use when creating your MySQL connection? Commented Sep 15, 2015 at 19:11
  • 1
    Thx for your answer. I edited my previous question with the mysql connection info. Commented Sep 15, 2015 at 19:15
  • 1
    Try adding charset="utf8" to your connection parameters. See this answer, this one and the pymsql docs for some more details. Commented Sep 15, 2015 at 19:20
  • Gread, glad I could help. I'll therefore flag your question with the appropriate duplicate, if I think that's correct you should be able to confirm that and immediately mark it as a dupe. Commented Sep 15, 2015 at 19:41

1 Answer 1

0

Not charset=utf8, you need to specify that your bytes are encoded cp1252, or perhaps latin1 (They are similar.)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.