robotframework中文显示乱码
问题描述:接口、数据库返回信息有中文的时候会显示unicode的样式,如图
解决方法:
1、robotframework为3.0.X
2、找到Python安装目录下的\Lib\site-packages\robot\utils\unic.py文件
引入json库:import json
将下面代码复制到如图位置,注意对齐方式
if isinstance(item, (list, dict, tuple)): try: item = json.dumps(item, ensure_ascii=False, encoding='cp936') except UnicodeDecodeError: try: item = json.dumps(item, ensure_ascii=False, encoding='cp936') except: pass except: pass
扩展:其中的cp936可用utf-8或者gbk编码格式去替换
也可以下载unic.py文件替换掉
下载地址:unic.py
# Copyright 2008-2015 Nokia Networks
# Copyright 2016- Robot Framework Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. from pprint import PrettyPrinter from .platform import IRONPYTHON, JYTHON, PY2
from .robottypes import is_bytes, is_unicode
import json if PY2: def unic(item):
if isinstance(item, unicode):
return item
if isinstance(item, (bytes, bytearray)):
try:
return item.decode('ASCII')
except UnicodeError:
return u''.join(chr(b) if b < 128 else '\\x%x' % b
for b in bytearray(item)) if isinstance(item, (list, dict, tuple)):
try:
item = json.dumps(item, ensure_ascii=False, encoding='utf-8')
except UnicodeDecodeError:
try:
item = json.dumps(item, ensure_ascii=False, encoding='gbk')
except:
pass
except:
pass
try:
try:
return unicode(item)
except UnicodeError:
return unic(str(item))
except:
return _unrepresentable_object(item) else: def unic(item):
if isinstance(item, str):
return item
if isinstance(item, (bytes, bytearray)):
try:
return item.decode('ASCII')
except UnicodeError:
return ''.join(chr(b) if b < 128 else '\\x%x' % b
for b in item)
try:
return str(item)
except:
return _unrepresentable_object(item) # JVM and .NET seem to handle Unicode normalization automatically. Importing
# unicodedata on Jython also takes some time so it's better to avoid it.
if not (JYTHON or IRONPYTHON): from unicodedata import normalize
_unic = unic def unic(item):
return normalize('NFC', _unic(item)) def prepr(item, width=400):
return unic(PrettyRepr(width=width).pformat(item)) class PrettyRepr(PrettyPrinter): def format(self, object, context, maxlevels, level):
try:
if is_unicode(object):
return repr(object).lstrip('u'), True, False
if is_bytes(object):
return 'b' + repr(object).lstrip('b'), True, False
return PrettyPrinter.format(self, object, context, maxlevels, level)
except:
return _unrepresentable_object(object), True, False def _unrepresentable_object(item):
from .error import get_error_message
return u"<Unrepresentable object %s. Error: %s>" \
% (item.__class__.__name__, get_error_message())
修改后运行脚本显示结果如下:
robotframework中文显示乱码的更多相关文章
- Linux中文显示乱码?如何设置centos显示中文
Linux中文显示乱码?如何设置centos显示中文 怎么设置Linux系统中文语言,这是很多小伙伴在开始使用Linux的时候,都会遇到一个问题,就是终端输入命令回显的时候中文显示乱码.出现这个情况一 ...
- Xshell个性化设置,解决Xshell遇到中文显示乱码的问题
在同事的推荐下,今天开始使用Xshell连接Linux,但是发现一个“遇到中文显示乱码”的问题, 同事的解决方案如下: 平常给Linux上传文件之前,先把文件转换成UTF-8编码形式, 然后设置Xsh ...
- (转)sqlplus中文显示乱码的问题
sqlplus中文显示乱码的问题 2010-07-19 11:33:26 分类: LINUX 在windows下sqlplus完全正常,可是到linux下,sqlplus中文显示就出问题了,总是显示“ ...
- GB2312、GBK和UTF-8三种编码以及QT中文显示乱码问题
1.GB2312.GBK和UTF-8三种编码的简要说明 GB2312.GBK和UTF-8都是一种字符编码,除此之外,还有好多字符编码.只是对于我们中国人的应用来说,用这三种编码 比较多.简单的说一下, ...
- SecureCRT中文显示乱码
环境:SecureCRT登陆REDHAT5.3 LINUX系统 问题:vi编辑器编辑文件时文件中的内容中文显示乱码,但是直接使用linux系统terminal打开此文件时中文显示正常,确诊问题出现在客 ...
- Linux下中文显示乱码问题
Linux下中文显示乱码问题 输出编码选utf-8 然后文件本身编码也要是utf-8
- linux中文显示乱码的解决办法
linux中文显示乱码的解决办法 linux中文显示乱码是一件让人很头疼的事情. linux中文显示乱码的解决办法:[root@kk]#vi /etc/sysconfig/i18n将文件中的内容修改为 ...
- CodeSmith exclude global 文件和文件夹问题 与 输入中文显示乱码问题
1.打开C:/Documents and Settings/你的用户名/Application Data/CodeSmith/v4.1/CodeSmithGui.config文件. 2.在<te ...
- MySQL 中文显示乱码以及中文查询条件返回0条结果的问题解决
最近关于中文显示乱码的贴子比较多,所以也做了个总结: 可以参考一下杨涛涛版主的<各种乱码问题汇总>http://topic.csdn.net/u/20071124/08/3b7eae6 ...
随机推荐
- requireJS的使用说明
RequireJS的目标是鼓励代码的模块化,它使用了不同于传统<script>标签的脚本加载步骤.可以用它来加速.优化代码,但其主要目的还是为了代码的模块化 requireJS 加载代码的 ...
- undefined vs. null
undefined vs. null 一.相似性 在JavaScript中,将一个变量赋值为undefined或null,老实说,几乎没区别. var a = undefined; var a = n ...
- Unit02: jQuery事件处理 、 jQuery动画
Unit02: jQuery事件处理 . jQuery动画 jQuery实现购物车案例 <!DOCTYPE html> <html> <head> <titl ...
- Erlang ets -- something about cache
都说用ets 写一个cache 太简单, 那就简单的搞一个吧, 具体代码就不贴了, 就说说简要的需求和怎么做(说设计有点虚的慌). 需求场景 >> 查询系统,对于主存储而言,一次写入多次查 ...
- (转)Inno Setup入门(十一)——完成安装后执行某些程序
本文转载自:http://blog.csdn.net/yushanddddfenghailin/article/details/17250901 有些时候我们的程序虽然能够很好的完成安装,但是程序的配 ...
- 【转】JMeter技巧集锦
JMeter是一个流行的用于负载测试的开源工具,具有许多有用的功能元件,如线程组(threadgroup),定时器(timer),和HTTP取样(sampler)元件.本文是对JMeter用户手册的补 ...
- java实现二叉树demo
二叉树(BinaryTree)是n(n≥0)个结点的有限集,它或者是空集(n=0),或者由一个根结点及两棵互不相交的.分别称作这个根的左子树和右子树的二叉树组成. 这个定义是递归的.由于左.右子 ...
- 关于v$BH
关于v$bh的相关字段值FILE# NUMBER Datafile identifier number (to find the filename, query DBA_DATA_FILES or V ...
- sql server xml 截断
c#读取 sql生成的xml时,发生阶段. 加,type 解决
- HTTP接口开发专题三(发送http请求,调用http接口的流程)
一.xml数据格式传输 1)构造xml参数:通过JAXB将java对象转换为xml 2)调用上一篇的http工具类的方法,发送请求到目的接口地址 3)返回的xml字符串结果,用JAXB进行解析成jav ...