0

While printing Cyrillic text from MySQL in my python3 program I get question marks instead of text.

The text I see in the MySQL table is Рожден ден.

The text I see in the python3 program is ?????? ???.

Type of row is class str.

For this list, I am using wxpython, wx module.

conn = pymysql.connect(host='localhost', database='Tasks', password='password', user='user')
        cursor = conn.cursor()

        cursor.execute('SELECT occasion,date,event FROM Important_Days')  
        records = cursor.fetchall()

        for row in records:
                pos = self.list1.InsertStringItem(0, row[0])
                self.list1.SetStringItem(pos, 1, str(row[1]))
                self.list1.SetStringItem(pos, 2, row[2])

        conn.close()
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153
  • [This question](https://stackoverflow.com/questions/15907509/python-cyrillic-decode) uses a different driver (MySQLdb) but the highest-scoring answer shows a way to configure MySQL to handle unicode. The accepted answer to [this question](https://stackoverflow.com/questions/17901459/python-mysqldb-returns-question-marks), again for MySQLdb, shows the parameters to set on the `connect` call. It's worth googling how to best configure MySQL to handle unicode. Take a backup before changing any database settings. – snakecharmerb Apr 28 '19 at 11:54
  • Possible duplicate of [python cyrillic decode](https://stackoverflow.com/questions/15907509/python-cyrillic-decode) – J_H Apr 28 '19 at 18:46
  • There are probably better duplicates but they depend on how exactly you configured things on the MySQL end. A general possible duplicate is https://stackoverflow.com/questions/46061496/python3-encoding-for-mysql-database – tripleee Apr 28 '19 at 19:33

1 Answers1

0

The question marks were created during the INSERTs, there is no way to get the Cyrillic out of them.

See "question mark" in Trouble with UTF-8 characters; what I see is not what I stored

See this for notes on Python: http://mysql.rjweb.org/doc.php/charcoll#python

Rick James
  • 135,179
  • 13
  • 127
  • 222