一、错误原因

在学习selenium自动化测试框架的时候,进行模仿浏览器搜索功能,输入英文是没问题,但是输入中文就报错,报错代码

    def test_baidu_search(self):
"""
这里一定要test开头,把测试逻辑代码封装到一个test开头的方法里。
:return:
"""
self.driver.find_element_by_id('kw').send_keys('时间')
time.sleep(1)
try:
assert '时间' in self.driver.title
print ('Test Pass.')
except Exception as e:
print ('Test Fail.', format(e))

报错内容:UnicodeDecodeError: 'utf8' codec can't decode byte 0xe6 in position 0: unexpected end of data

二、解决办法

在中文后加.decode("utf-8") 设置为utf-8

 assert '时间'.decode("utf-8") in self.driver.title

python错误:UnicodeDecodeError: 'utf8' codec can't decode byte 0xe6 in position 0: unexpected end of data的更多相关文章

  1. 爬虫 -- UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe6 in position 301: unexpected end of data

     errors参数有3个值:strict,  ignore,  replace html.decode("utf-8"),这种形式有时会报错,那么修改为下面形式,将decode函数 ...

  2. python join() 提示UnicodeDecodeError: 'utf8' codec can't decode byte 0xcb in position 0: unexpected end of的原因及解决办法

    问题: 在使用join()将列表元素连接成字符串时出错如下 return split.join(result) UnicodeDecodeError: 'utf8' codec can't decod ...

  3. 解决utf8' codec can't decode byte 0xe5 in position 0: unexpected end of data

    使用unicode对象的话,除了这样使用u标记,还可以使用unicode类以及字符串的encode和decode方法. unicode类的构造函数接受一个字符串参数和一个编码参数,将字符串封装为一个u ...

  4. python 错误: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)

    参照:http://www.runoob.com/django/django-form.html 做了个表单提交和回显,但是报了以上错误 查资料发现是 python从request取值的是unicod ...

  5. Python:出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in position 0: invalid continuation byte问题

    我在导入一个csv文件的时候出现了一个问题 报错的内容是这样的: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc9 in positio ...

  6. tensorflow UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

    tensorflow读取图像出现错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid s ...

  7. 用python3读CSV文件,出现UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid con

    使用pd.read_csv()读csv文件时,出现如下错误: UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xd0 in position ...

  8. 解决Requests中文乱码【有用】,读取htm文件 读取txt文件报错:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 0

    打开这个网址https://blog.csdn.net/chaowanghn/article/details/54889835 python在open读取txt文件时,出现UnicodeDecodeE ...

  9. mysql-connector-python取二进制字节时报错UnicodeDecodeError:'utf-8' codec can't decode byte 0xb0 in position 0

    在储存用户密码时,我使用了hmac算法对用户密码加密,加密出来的hash值是一个二进制字节串,我把这个字节串存到mysql的password字段,password字段的数据类型是varbinary. ...

随机推荐

  1. 安装VisualSVN Server 报错The specified TCP port is occupied

    安装过程中报错,如下图所示. The specified TCP port is occupied by another service.Please stop that service or use ...

  2. 快速搭建Spring Boot项目

    Spring boot是Spring推出的一个轻量化web框架,主要解决了Spring对于小型项目饱受诟病的配置和开发速度问题. Spring Boot 包含的特性如下: 创建可以独立运行的 Spri ...

  3. bzoj千题计划173:bzoj1257: [CQOI2007]余数之和sum

    http://www.lydsy.com/JudgeOnline/problem.php?id=1257 k%i=k-int(k/i)*i 除法分块,对于相同的k/i用等差序列求和来做 #includ ...

  4. 织梦自定义表单通过ajax提交的实现方法

    自定义表单通过ajax判断,提交不用跳转页面,提高用户体验.具体方法如下: html表单代码部分,就提交按钮改成botton,,添加onclick事件 表单代码: <form action=&q ...

  5. linux scp上传文件到其他机器上

    scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的.可能会稍微影响一下速度.当你服务器 ...

  6. Javascript 常用的工具函数,更新中...

    1.时间戳转为格式化时间 /** * 时间戳转为格式化时间 * @Author chenjun * @DateTime 2017-11-10 * @param {[date]} timestamp [ ...

  7. 连接mysql提示Establishing SSL connection without server's identity verification is not recommended错误

    Establishing SSL connection without server's identity verification is not recommended. According to ...

  8. POJ 2485 Highways( 最小生成树)

    题目链接 Description The islandnation of Flatopia is perfectly flat. Unfortunately, Flatopia has no publ ...

  9. linux源码安装nginx

    任务目标:源码安装nginx,作为web服务修改配置文件,让配置生效,验证配置 首先要去官网nginx.org下载一个tar包: tar xvf 解包 进入到解包出来的目录,对configure进行配 ...

  10. APScheduler API -- apscheduler.triggers.interval

    apscheduler.triggers.interval API Trigger alias for add_job(): interval class apscheduler.triggers.i ...