python2.7 编码解码问题
已经用chardet.detect 得出字符串的编码是gb2312,然后再str.decode(encoding='gb2312', errors='strict').还是报错UnicodeDecodeError: 'gb2312' codec can't decode bytes
_buff = self.ch.recv(nbyte)
print (chardet.detect(_buff))
try:
_buff = _buff.decode(encoding='UTF-8', errors='strict')
except UnicodeDecodeError:
_buff = _buff.decode(encoding='gb2312', errors='strict')