April 8th, 2013, 01:21 PM
Character set problems from MySQL cursor.fetchall
I am trying to retrieve strings from a MySQL query in Python and the string is a Latin Croatian collation. Some of the characters are not making it and what I get is something like,
I tried copying and pasting the suspect characters directly into the Python program to see if I could print the string directly and found that file itself would not take the string unless I changed the file itself from ASCII to UTF-8. Once I did that the string would not print and debug referred me to a link,
(('Karad\x9ei?',), ('Stani\x9ai? & Simatovi?',), ('Bo\x9akoski & Tar?ulovski',))
Which directed me to put a magic comment at the top of the program,
This worked and I was able to print the suspect characters,
from the python program. However, I was still unable to print the characters correctly from the MySQL cursor.fetchall.
I have had similar problems in Perl that I was unable to fix on my own and the solution provided me I still do not understand. Also, finally figuring out how to file these characters in MySQL itself is only resolved in later databases, 5.6 or 5.7, I think.
What do I need to do to preserve these characters from a MySQL query?