问题描述:接口、数据库返回信息有中文的时候会显示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中文显示乱码的更多相关文章

  1. Linux中文显示乱码?如何设置centos显示中文

    Linux中文显示乱码?如何设置centos显示中文 怎么设置Linux系统中文语言,这是很多小伙伴在开始使用Linux的时候,都会遇到一个问题,就是终端输入命令回显的时候中文显示乱码.出现这个情况一 ...

  2. Xshell个性化设置,解决Xshell遇到中文显示乱码的问题

    在同事的推荐下,今天开始使用Xshell连接Linux,但是发现一个“遇到中文显示乱码”的问题, 同事的解决方案如下: 平常给Linux上传文件之前,先把文件转换成UTF-8编码形式, 然后设置Xsh ...

  3. (转)sqlplus中文显示乱码的问题

    sqlplus中文显示乱码的问题 2010-07-19 11:33:26 分类: LINUX 在windows下sqlplus完全正常,可是到linux下,sqlplus中文显示就出问题了,总是显示“ ...

  4. GB2312、GBK和UTF-8三种编码以及QT中文显示乱码问题

    1.GB2312.GBK和UTF-8三种编码的简要说明 GB2312.GBK和UTF-8都是一种字符编码,除此之外,还有好多字符编码.只是对于我们中国人的应用来说,用这三种编码 比较多.简单的说一下, ...

  5. SecureCRT中文显示乱码

    环境:SecureCRT登陆REDHAT5.3 LINUX系统 问题:vi编辑器编辑文件时文件中的内容中文显示乱码,但是直接使用linux系统terminal打开此文件时中文显示正常,确诊问题出现在客 ...

  6. Linux下中文显示乱码问题

    Linux下中文显示乱码问题 输出编码选utf-8 然后文件本身编码也要是utf-8

  7. linux中文显示乱码的解决办法

    linux中文显示乱码的解决办法 linux中文显示乱码是一件让人很头疼的事情. linux中文显示乱码的解决办法:[root@kk]#vi /etc/sysconfig/i18n将文件中的内容修改为 ...

  8. CodeSmith exclude global 文件和文件夹问题 与 输入中文显示乱码问题

    1.打开C:/Documents and Settings/你的用户名/Application Data/CodeSmith/v4.1/CodeSmithGui.config文件. 2.在<te ...

  9. MySQL 中文显示乱码以及中文查询条件返回0条结果的问题解决

      最近关于中文显示乱码的贴子比较多,所以也做了个总结: 可以参考一下杨涛涛版主的<各种乱码问题汇总>http://topic.csdn.net/u/20071124/08/3b7eae6 ...

随机推荐

  1. 关于ng-class,ng-style的用法

    ng-class的使用几种方式 (1):利用双向数据绑定(className根据chang2的值去匹配类) <div class="{{className}}">... ...

  2. laravel 中事务的使用

    在laravel5.3中使用事务 可以直接使用\DB::beginTransaction();使用 前提是数据库表必须支持事务,目前mysql中表类型只有InnoDb支持事务 想要在一个数据库事务中运 ...

  3. 批处理实现mysql的备份

    脚本 @echo off echo. echo MySQL数据库备份 echo ***************************** echo. echo 今天是 %date% echo 时间是 ...

  4. JDK 8 - Method Reference 分析

    Java SE 8 在 Java 语言层面上新增了 lambda expression 的功能,使得 Java 具备了函数式语言的能力 - 可以将函数作为方法参数传递,即 code as data. ...

  5. java代码---------实现布尔型的功能,是否执行下一步的关键

    总结:灵活 package com.sads; import java.io.BufferedReader; import java.io.IOException; import java.io.In ...

  6. 将子类对象引用赋值给超类对象 JAVA 编译时多态性

    将子类对象引用赋值给超类对象 JAVA 编译时多态性(转) (2012-05-10 11:24:05) 转载▼ 标签: 杂谈 分类: 也无晴_soft 1.通过将子类对象引用赋值给超类对象引用变量来实 ...

  7. ConcurrentHashMap放入null值报错

    //ConcurrentHashMap源码: /** Implementation for put and putIfAbsent */ final V putVal(K key, V value, ...

  8. 关于ie6中绝对定位或浮动的div中既有向左float也有向右float时候如何让外层div自适应宽度的解决方案--

    一个详细的说明请见: http://www.cnblogs.com/yiyang/p/3265006.html 我的问题大约为,如下代码: <!DOCTYPE html PUBLIC " ...

  9. leetcode836

    public class Solution { public bool IsRectangleOverlap(int[] rec1, int[] rec2) { ], rec2[]) < Mat ...

  10. TBluetoothLEDevice.UpdateOnReconnect

    System.Bluetooth.TBluetoothLEDevice.UpdateOnReconnect Description Indicates whether the manager auto ...