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'))

转载于:https://www.cnblogs.com/Javauser/p/10679453.html

你可能感兴趣的:(数据库,python)