views:

31

answers:

1

Next question about russian encoding, mssql and python.

I have this simple code:

import pymssql
import codecs
conn=pymssql.connect(host='localhost:1433', user='sa',  password='password', database='TvPgms')
cur = conn.cursor()
cur.execute('SELECT TOP 5 CAST( Name AS nvarchar(400) ), CONVERT(nvarchar(400), idProgram) FROM dbo.Programs')
p=cur.fetchone()
h=p[0]
d=codecs.lookup(h)
print h
conn.close()

I get the error: LookUp Error : Unnown Encoding: ????? ?????? ???????

I cant reed russian varchar filds from MSSQL. But when i just print string in the same code all is ok, it print me normal russian characters. Who know how?

If I truing just print h insted of codecs.lookup than i get no error, but it prints me ???????? ?????????

+2  A: 

codecs.lookup takes an encoding name, not some random string, and you probably don't need it here anyway. I think at the moment you cannot reliably print Unicode strings from Python to the Windows console due to deep technical problems. Try writing to a file or using the WriteConsoleW function directly (via ctypes) instead.

Philipp
It do not help, I tried write in file. In file I get the same question marks.
Pol
Maybe you know what type of encoding send me mssql server respond?
Pol
No, and if there are already errors when trying to work with literal strings, it doesn't matter yet.
Philipp
So what shoul i do?
Pol
laurent-rpnet
Ok! thanks! I decide to use odbc module. It works perfectly.
Pol