Scrapy爬虫向数据库写入数据时报错:

UnicodeEncodeError:'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)

解决方案:

1.我使用的是SQLALchemy,在create_engine()中添加charset=utf8和encoding='utf-8’

engine = create_engine(mysql+mysqldb://”root:123456@127.0.0.1:3306/test?charset=utf8”,encoding=”utf-8”)

2.修改mysql配置文件

1.获取root权限

sudo -i

2.进入配置文件所在路径

cd /etc/mysql/mysql.conf.d

3.备份

cp -p mysqld.cnf mysqld.cnf.bak

4.用vim打开mysqld.cnf,添加以下内容

mysqld
character_set_server = utf8

5.重新加载配置文件

/etc/init.d/mysql reload

UnicodeEncodeError:'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)的更多相关文章

  1. UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-5: ordin al not in range(128)——解决方案备注

    在vim中使用ycm插件时,偶尔会出现: “UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-5: ord ...

  2. Python编码问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(12

    今天安装了PyScripter编辑器,刚要写代码,突然就出现异常: <span style="font-size:14px;color:#ff0000;">>&g ...

  3. 【Python】【BugList12】python自带IDLE执行print(req.text)报错:UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 93204-93204

    [代码] # -*- coding:UTF-8 -*- import requests if __name__ == '__main__': target = 'https://unsplash.co ...

  4. pip install 安装出现问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position XX的解决办法

    pip install 安装出现问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position XX的解决办法 转自c ...

  5. UnicodeEncodeError:'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256) Scrapy

    1.使用scrapy对数据进行入库时,出现如下错误: UnicodeEncodeError:'latin-1' codec can't encode characters in position 0- ...

  6. Python - requests发送请求报错:UnicodeEncodeError: 'latin-1' codec can't encode characters in position 13-14: 小明 is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

    背景 在做接口自动化的时候,Excel作为数据驱动,里面存了中文,通过第三方库读取中文当请求参数传入 requests.post() 里面,就会报错 UnicodeEncodeError: 'lati ...

  7. python:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

    # 将默认编码设为utf-8 # 否则会报错: # UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ...

  8. python+selenium运行报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

    使用python+selenium运行自动化脚本时,打印某一段文字出现UnicodeEncodeError: 'ascii' codec can't encode characters in posi ...

  9. web.py+mysql插入中文提示query = query.encode(charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 86-100

    对于中文编码的问题,总会出现各种各样恶心的错误,还不知道应该怎么解决,首先,你从最开头就应该关注编码问题,尽量保证所有的编码方式都是一致的 用python+web.py+mysql来写程序,首先要保证 ...

随机推荐

  1. mysql 计算经纬度函数(米)

    ) CHARSET utf8mb4 begin return ROUND( * ASIN( SQRT( POW( SIN( ( lat1 ) ), ) ) ) * POW( SIN( ( lon1 ) ...

  2. PyQt5系列教程(五)制作fastboot烧写器

    软硬件环境 Windows 7 Python 3.4.2 PyQt 5.5.1 PyCharm 5.0.2 前言 fastboot是针对Android设备的一种刷机方式,它比recovery更底层,刷 ...

  3. HyberLedger Fabric学习(3)-chaincode学习(开发者)

    参考:http://hyperledger-fabric.readthedocs.io/en/latest/chaincode4ade.html chaincode是由go语言写的,实现了定义的接口. ...

  4. Shell脚本的调试方法

    Shell脚本的调试方法 Shell提供了一些用于调试脚本的选项,如下所示: -n    读一遍脚本中的命令但不执行,用于检查脚本中的语法错误 -v    一边执行脚本,一边将执行过的脚本命令打印到标 ...

  5. YUM CentOS 7 64位下mysql5.7安装配置

    配置YUM源 在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/yum/ #下载mysql源安装包 # wget http://dev ...

  6. BTM事务配置

    请参考原贴:http://thinkdifferent.iteye.com/blog/1450433 Tomcat6上配置BTM 博客分类: practice tomcatjava )去http:// ...

  7. springboot+shiro+jwt

    1.添加依赖 <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-sp ...

  8. 01c-1: 主流长远

  9. 流形学习 (Manifold Learning)

    流形学习 (manifold learning) zz from prfans............................... dodo:流形学习 (manifold learning) ...

  10. Visual Studio C++ include与library

    首先介绍几种目录: 1. 系统路径 系统路径在vc中是"Properties->Configuration Properties -> VC++ Directories" ...