python bug
2015-09-01 12:16
441 查看
bug1
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
这是由于Python编码格式的原因,在导入包的后面添加下面的语句
sys.setdefaultencoding(‘utf8’)
设置默认编码格式为utf8
bug2
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u79d2' in position 5: ordinal not in range(256)
MySQLdb正常情况下会尝试将所有的内容转换为Latin1字符集处理,所以解决方法见下。
解决方法:
db = MySQLdb.connect(host="localhost", user = "root", passwd = "", db = "testdb", use_unicode=True, charset="utf8")
bug3
_mysql_exceptions.OperationalError: (1136, "Column count doesn't match value count at row 1") 解决方法:数据库表的列名与程序插入数据库的字段名保持一致。
相关文章推荐
- Python实现身份证号码解析
- python2.7学习笔记(7) ——函数式编程
- Python--生成器
- python logging 日志详细配置
- python string包——简易函数使用
- Python学习----高级特性
- python 查找指定内容的txt文件
- python编码问题
- 【转】python import的用法
- python dom解析API目录
- python实现八皇后
- python中的xml.dom的使用
- Python Unitest 源码阅读:概述
- Python uuid
- python调用Go代码
- Python计算Project Euler Problem 3
- Ubuntu Python 环境配置
- python django 数据库查询方法总结
- 【Python学习日记】 第 b1fd 一天
- Python模拟登陆大连交通大学教务在线