python mysql数据库 'latin-1' codec can't encode character错误问题解决
2024-09-05 11:31:24
"UnicodeEncodeError:'latin-1' codec can't encode character ..."
This is because MySQLdb normally tries to encode everything to latin-1. This can be fixed by executing the following commands right after you've etablished the connection:
意思就是MySQLdb正常情况下会尝试将所有的内容转为latin1字符集处理
所以处理方法就是,设置连接和游标的charset为你所希望的编码,如utf8。
db.set_character_set('utf8')
dbc.execute('SET NAMES utf8;') dbc.execute('SET CHARACTER SET utf8;')
dbc.execute('SET character_set_connection=utf8;')
db是connection连接,dbc是数据库游标
http://stackoverflow.com/questions/3942888/unicodeencodeerror-latin-1-codec-cant-encode-character
最新文章
- 手机浏览器浏览WebApp弹出的键盘遮盖住文本框的解决办法
- Swift 和 C# 的语法比较
- ES6之let(理解闭包)和const命令
- Oracle的分页查询
- MyBatis插入多条
- PHP实现获得一段时间内所在的所有周的时间
- 本地或者是koala软件编译less文件为css
- shell命令:echo命令详解
- 移动支付之智能IC卡与Android手机进行NFC通信
- WebForm 控件(一)、连接数据库
- Go 从入门到精通(三)字符串,时间,流程控制,函数
- 201521123106 《Java程序设计》第8周学习总结
- python生成随机图形验证码
- Ambari自定义Service
- Python实现矿池
- vue(v-html)和scss的使用问题
- DirectX using C++_error X3539:ps1_x is no longer supported...解决方案
- 转载:分布式文件系统 - FastDFS 在 CentOS 下配置安装部署(1)
- 浅谈table、form 标签
- GO1.6语言学习笔记2-安装配置及代码组织