美文网首页
【com】命令行返回ascii码错误问题处理

【com】命令行返回ascii码错误问题处理

作者: EldonZhao | 来源:发表于2016-11-24 10:38 被阅读22次

    问题现象

    [root@BFJD-PSC-BCEC-CORE-SV26 ~]# neutron port-list
    'ascii' codec can't encode characters in position 180791-180794: ordinal not in range(128)

    Debug信息

    问题分析

    • port信息中包含中文字符

    • neutronclient format时不支持ascii code

    File "/usr/lib/python2.7/site-packages/cliff/formatters/table.py", line 56, in emit_list

    问题处理

    • 修改table.py中相关代码

    vim /usr/lib/python2.7/site-packages/cliff/formatters/table.py

    修改前:
        def emit_list(self, column_names, data, stdout, parsed_args):
            ......
            formatted = x.get_string(fields=column_names)
            stdout.write(formatted)
            stdout.write('\n')
            return
    
        def emit_one(self, column_names, data, stdout, parsed_args):
            ......
            formatted = x.get_string(fields=('Field', 'Value'))
            stdout.write(formatted)
            stdout.write('\n')
    
    修改后:
        def emit_list(self, column_names, data, stdout, parsed_args):
            ......
            formatted = x.get_string(fields=column_names)
            formatted = formatted.encode('utf-8')
            stdout.write(formatted)
            stdout.write('\n')
            return
    
        def emit_one(self, column_names, data, stdout, parsed_args):
            ......
            formatted = x.get_string(fields=('Field', 'Value'))
            formatted = formatted.encode('utf-8')
            stdout.write(formatted)
            stdout.write('\n')
    
    • 重新查询port信息:
    neutron port-list

    相关文章

      网友评论

          本文标题:【com】命令行返回ascii码错误问题处理

          本文链接:https://www.haomeiwen.com/subject/pvdbpttx.html