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 ...
随机推荐
- jdk1.8新特性之接口default方法
众所周知,default是java的关键字之一,使用场景是配合switch关键字用于条件分支的默认项.但自从java的jdk1.8横空出世以后,它就被赋予了另一项很酷的能力——在接口中定义非抽象方法. ...
- golang获取packed struct的大小
网络协议里面,很可能遇到自定义的封包,对应到c里面的是 typedef struct _PackageHeader { int headerLen; int timeStamp; short cmd ...
- Server Tomcat v9.0 Server at localhost failed to start.
最近老是出现这样的问题,在网上找了很多方法都不行,试着把Tomcat重新配置了一下就好了,事后找到一个博客,试了一下也可以使用
- python md5 请求 构造
-----------------md5加密的方法:---------------------------------- import hashlib m = hashlib.md5() ...
- Codeforces 982C(dfs+思维)
C. Cut 'em all! time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- sys模块的问题,深浅COPY的应用场景,元祖与购物车程序练习-打印彩色\033[31;1m--------\033[0m
打印彩色:%s为变量,格式化 print("Added %s into shopping cart,your current balance is \033[31;1m%s\033[0m&q ...
- mysql 优化 (1)
提高IOPS能力的几种方法换SSD,PCIE-SSD(提高IO效率,普通SAS盘5000以内的iops,而新设备可达到数万或者数十万iops)少做IO的活(合并多次读写为一次,或者前端加内存CACHE ...
- Linut ssh sftp服务重启
在网上,收了半天,终于找到这个,记录一下~哈~ RedHat Linux 重启SSH /etc/init.d/sshd restart 重启SFTP /etc/init.d/vsftpd restar ...
- scrapy-redis组件
scrapy-redis组件 可以帮你保存任务和过滤url redis 数据库 安装 # 下载 wget http://download.redis.io/releases/redis-3.0.6.t ...
- 如何将字符串去重复demo工具
//方法一:使用集合的indexOf方法 public static void one(){ String string="aaaaaakkkkkkmnf";//需去重复的字符串s ...