处理微信接口+MySQLdb的中文乱码

阅读时间: 少于 1 分钟

微信接口+MySQLdb时,查询中文总会出现乱码问题,把python设置为utf8、mysql的varaibles设置为utf8也没用,最后发现是微信接口返回数据作怪:

微信接口中,中文字符的编码格式是:

{'confidence': 0.73, 'encoding': 'windows-1252'}

所以,微信返回数据时需要设置一下:

content = content.encode('utf8')

标签:

分类:

最新的: