Robot Framework:日誌輸出中文Unicode編碼
阿新 • • 發佈:2018-12-06
robotframework 輸出日誌時,中文顯示為Unicode編碼 。
修改方法:
在Python27\Lib\site-packages\robotframework-3.0.4-py2.7.egg\robot\utils\unic.py檔案中新增以下程式碼
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)
修改後,重啟robotframework後,輸出日誌正常