一、场景
使用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博客
- character undefined 39 position charmapcharacter undefined 39 position unicodeencodeerror characters 39 position character multibyte position illegal encountered unexpected character position 39 unicodeencodeerror character multibyte unicodedecodeerror multibyte 39 position unicodedecodeerror byte 39 position unicodeencodeerror flask-mail characters 39 39 unicodeencodeerror character错误 39 position decode codec