Python 排错UnicodeEncodeError 'ascii' codec can't encode character 错误解决方法
Python UnicodeEncodeError 'ascii' codec can't encode character 错误解决方法
by:授客 QQ:1033553122
错误描述:
python编程时(测试环境 Python 2.7),遇到如下错误:
Traceback (most recent call last):
File "F:/project/1dcq-o2o-web/selenium2wd/main.py", line 37, in
test_case.run()
File "F:\project\1dcq-o2o-web\selenium2wd\test_case.py", line 111, in run
test_case_step.run_tc_steps(tc_step, test_case_datagroup)
File "F:\project\1dcq-o2o-web\selenium2wd\test_case_step.py", line 38, in run_tc_steps
self.run_function_in_step(command, inparameters, test_case_datagroup)
File "F:\project\1dcq-o2o-web\selenium2wd\test_case_step.py", line 51, in run_function_in_step
inparameters = inparameters.decode('utf-8')
File "D:\Program Files\python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\uff0c' in position 15: ordinal not in range(128)
其中inparameters包含右侧字符:||,|| (说明:这里逗号使用的是中文逗号 ,
解决方法:
如下,代码开头处添加如下代码
import sys
reload(sys)
sys.setdefaultencoding('utf8')
作者:授客
微信/QQ:1033553122
全国软件测试QQ交流群:7156436
Git地址:https://gitee.com/ishouke
友情提示:限于时间仓促,文中可能存在错误,欢迎指正、评论!
作者五行缺钱,如果觉得文章对您有帮助,请扫描下边的二维码打赏作者,金额随意,您的支持将是我继续创作的源动力,打赏后如有任何疑问,请联系我!!!
微信打赏
支付宝打赏 全国软件测试交流QQ群