码迷,mamicode.com
首页 > 数据库 > 详细

爬虫学习之-python插入mysql报错

时间:2018-09-20 21:25:43      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:medium   解决   pos   article   爬虫   通过   name   l数据库   har   

异常:‘latin-1‘ codec can‘t encode characters in position 62-66: ordinal not in range(256)

 

用Python通过pymysql往MySQL数据库中插入数据时,插入的字段含有中文,出现异常:

‘latin-1‘ codec can‘t encode characters in position 62-66: ordinal not in range(256)

数据库连接语句:

db=pymysql.connect(host="localhost",user="root",passwd="mysql",db="test_db")

解决办法:

把数据库连接语句改为:

db=pymysql.connect(host="localhost",user="root",passwd="mysql",db="test_db",port=3306,charset=‘utf8‘)

爬虫学习之-python插入mysql报错

标签:medium   解决   pos   article   爬虫   通过   name   l数据库   har   

原文地址:https://www.cnblogs.com/php-linux/p/9683089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!