Connection to the database ( Pervasive ).
The base encoding is cp866 . OS - Windows
I can not display the Cyrillic alphabet in the console.
import pyodbc dbfile = pyodbc.connect('DSN=test') cursor = dbfile.cursor() cursor.execute("select NameAccount from account_dbt") row = cursor.fetchall() for l in range(4): t = str(row[l][0]) print(t) Result:
ЋЋЋ ђ®¬ иЄ Ћ¤Ё(Romashka odin) ЋЋЋ ђ®¬ иЄ Ћ¤Ё(Romashka odin) - 2 ЋЋЋ ђ®¬ иЄ Ћ¤Ё(Romashka odin) - 3 ЋЋЋ ђ®¬ иЄ Ћ¤Ё(Romashka odin) - 4 I tried this:
t = str(row[l][0]).encode('utf-8') Result:
b'\xd0\x8b\xd0\x8b\xd0\x8b \xd1\x92\xc2\xae\xc2\xac\xc2\xa0\xd0\xb8\xd0\x84\xc2\xa0 \xd0\x8b\xc2\xa4\xd0\x81\xc2\xad(Romashka odin)' b'\xd0\x8b\xd0\x8b\xd0\x8b \xd1\x92\xc2\xae\xc2\xac\xc2\xa0\xd0\xb8\xd0\x84\xc2\xa0 \xd0\x8b\xc2\xa4\xd0\x81\xc2\xad(Romashka odin) - 2' b'\xd0\x8b\xd0\x8b\xd0\x8b \xd1\x92\xc2\xae\xc2\xac\xc2\xa0\xd0\xb8\xd0\x84\xc2\xa0 \xd0\x8b\xc2\xa4\xd0\x81\xc2\xad(Romashka odin) - 3' b'\xd0\x8b\xd0\x8b\xd0\x8b \xd1\x92\xc2\xae\xc2\xac\xc2\xa0\xd0\xb8\xd0\x84\xc2\xa0 \xd0\x8b\xc2\xa4\xd0\x81\xc2\xad(Romashka odin) - 4' Article on Habré about encoding also did not clarify.
How to display the text in a readable form?