I have a ms sql server, and I need to access its database in ubuntu pc. so I use freetds/pyodbc to query data.
OS: ubuntu 14.04
pyodbc: pyodbc-3.0.10
When ms sql server has a special character (ß), I can not get correct result.
cnxn = pyodbc.connect(
'DRIVER=FreeTDS;'
'SERVER=10.1.1.1;'
'PORT=1433;'
'DATABASE=db;'
'UID=sa;'
'PWD=111;'
'CHARSET=UTF-8;'
'unicode_results=True'
'TDS_Version=8.0')
cursor.execute("select * from test")
for row in cursor.fetchall():
print row[0]
row[0] will contain character ß, but when I use "".join("{:02x}".format(ord(c)) for c in row[0])
.
I found that row is use 0xdf
for ß, from http://lwp.interglacial.com/appf_01.htm, 0xdf
is raw encoding, as UTF8, it should be 0xC3,0x9F
.
Why pyodbc do not return UTF8 encoding data, and how can I decode it in python 2.7, Thanks~