I read the text from the database and get questions instead of Russian characters:

? ????? ????? ?????, ? ??? ???? ??? 

Code:

 db = pymysql.connect(************) cursor = db.cursor() query = "SELECT username, message FROM messages WHERE anon = 1 ORDER BY id DESC LIMIT " + count cursor.execute(query) result = cursor.fetchall() print(result) messages = [] for item in result: messages.append(item[0] + ": " + item[1]) messages = " | ".join(messages).replace("\r\n", "") print(messages) utils.mess(s, "/w " + username + " " + messages) db.close() 

Password and login DB replaced with asterisks

How to fix this error?

  • one
    Remove the extra code. If print (result) already prints some questions, then the rest of the code is no longer needed. - jfs
  • Show print (ascii (result)) - jfs
  • I already fixed, added charset = 'utf8' in connection to the database - Liptonus

1 answer 1

In the connection to the database, charset='utf8' added at the end. This solved the problem.