Sunday, May 4th, 2025

pymssql查询结果中文乱码处理

解决方案:
乱码的地方加上.encode(‘latin1’).decode(‘gbk’),先编码成SQL server支持的编码格式,再解码成中文。
例子:
cursor = connect.cursor() # 创建一个游标对象,python里的sql语句都要通过cursor来执行。
cursor.execute(my_sql) # 执行sql语句
print(cursor.fetchall())
for item in iter(cursor.fetchall()):
print(item[1].encode('latin1').decode('gbk'))

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注