【python】解决'charmap' codec can't decode byte 0x8d in position 1974: character maps to <undefined>

发布时间 2023-06-21 16:37:34作者: 代码诠释的世界

一、场景

    使用paramiko连接ssh服务器,处理回显,然后报错

 

二、处理方法

问题代码    

# encoding = chardet.detect(data)
# if encoding.get('encoding'):
#     encode = encoding.get('encoding')
# else:
#     encode = "ascii"
data = data.decode(encode).strip()

本意是想根据自动检测编码格式并解码

因为是linux,默认utf-8, 所以咱直接写死

data = data.decode("UTF-8").strip()

然后正常解决

 

 

参考链接:

(89条消息) 解决‘charmap‘ codec can‘t decode byte in position: character maps to <undefined>_狂小虎的博客-CSDN博客