在项目中发现这样一个问题:sqlserver数据库编码为gbk,使用python3.4+pymssql 查询,中文乱码,经过一番思考问题解决,下面把解决办法分享给大家:
conn = pymssql.connect(host="192.168.122.141",
port=1433,
user="myshop",
password="oyf20140208HH",
database="mySHOPCMStock",
charset='utf8',
as_dict=True) cur = conn.cursor()sql = "select top 10 [ID],[Name] from [User]"cur.execute(sql)list = cur.fetchall()for row in list: print(row["ID"],row["Name"].encode('latin-1').decode('gbk'))