One - One Code All

Blog Content

pymysql数据库连接UnicodeEncodeError

Python MySQL   2012-10-13 19:47:22

问题:pymysql 连接数据库的时候出现:UnicodeEncodeError: 'latin-1' codec can't encode character u'\u201c' in position 0: ordinal not in range(256)

解决:连接参数里增加charset="utf8" 参数即可。
db = pymysql.connect(host, user, passwd, db, use_unicode=True, charset="utf8")


上一篇:python操作mysql,pymysql操作方法
下一篇:mysql数据库性能优化

The minute you think of giving up, think of the reason why you held on so long.