Python中文乱码问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Grandaunt/article/details/80816463

获取sqlserver数据库数据时遇到中文乱码问题
解决方法:

1.头部加#coding:gb2312
2. pymssql.connect加charset=”GBK” pymssql.connect(host=self.host, user=self.user, password=self.pwd, database=self.db, charset=”GBK”)
3.sql数据加l.encode(‘gb2312’) ms.ExecQuery(newsql.encode(‘gb2312’))

由于链接的是sqlserver数据库,so设置的是GBK,一般设置成utf-8

猜你喜欢

转载自blog.csdn.net/Grandaunt/article/details/80816463