开发者

Next question about russian encoding, mssql and python

开发者 https://www.devze.com 2023-01-06 00:13 出处:网络
Next question about russian encoding, mssql and python. I have this simple code: import pymssql import codecs

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开发者_如何学JAVA of codecs.lookup than i get no error, but it prints me ???????? ?????????


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号