python3.4+pymssql 中文乱码问题解决
作者:互联网
问题: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'))
标签:cur,乱码,python3.4,pymssql,Name,conn,row 来源: https://www.cnblogs.com/Javauser/p/10679453.html