0

I'm trying to read data from a MySql database. Everything is correct except when I have to receive words with an accent or the character 'ñ'

I have reviewed the collation of my database. I have it configured in utf8_unicode_ci in the table and in the column.

I use python 2.7.8 and I have tried to decode and unicode and I can not write well the result of the tables. I always get:

Baño -> Ba\xf1o

Lámina -> L\xe1mina

I launch the query from RIDE (1.5.2.1) under Windows 10.

Any ideas?

Thank you.

Marta79
  • 91
  • 1
  • 3
  • 14

1 Answers1

1

How are you "receiving" the text? ñ, when encoded as hex e1 is encoded as latin1. (Actually any of cp1250, dec8, latin1, latin2, latin5, but probably latin1, since that is the old default for MySQL.)

If you actually have e1 in the client, then tell MySQL that you have latin1. It is OK to have the database tables set to utf8 -- MySQL will transliterate as you do the stores/fetches.

It would be better to have utf8 everywhere.

Here are my notes on Python: http://mysql.rjweb.org/doc.php/charcoll#python Note that that section ends with a link to an issue with the old Python 2.7, which you seem to be using: Flask_SQLAlchemy, MySQL, store Swedish characters å, ä, ö?

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • Thank you very much, the following link has been very useful: http://mysql.rjweb.org/doc.php/charcoll#python Here I saw that I had to add dbcharset = 'utf8' in the connection. With this the problem has been solved. Now I receive correctly MySQL characters with accents and with 'ñ'. Many thanks! – Marta79 Dec 05 '17 at 09:45
  • @Marta79 - Glad the link helped. Alas, the link is a jumble of things. Did you see anything 'wrong'? Should I rearrange it? Other critique? (I've never used Python.) – Rick James Dec 05 '17 at 16:44