robotframework 列表,字典,元组输出中文乱码解决方案

在用RF写接口自动化脚本过程中,经常会输出列表或者字典,但是中文会显示乱码,在网上找到的解决办法是:

在python的Lib\site-packages\robot\utils下有个unic.py文件,打开,先导入json

再修改下面的代码,再重启RF就好了

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)
 
 
本来想截图,但是上传不了

猜你喜欢

转载自www.cnblogs.com/yangtou45du/p/10855746.html