解码方式错误,先获取编码方式,在进行解码
获取编码方式
res = b"\xb2......"
encode_type = (chardet.detect(res)).get("encoidng")
str_res = res.decode(encode_type)
当遇到解码错误时,文章提出了先使用chardet库的detect方法检测数据的编码类型,然后用获取到的编码方式对数据进行解码的解决方案。例如,变量res含有xb2......的内容,通过chardet检测得到其编码类型encode_type,然后使用res.decode(encode_type)进行正确解码,转化为str_res。
解码方式错误,先获取编码方式,在进行解码
获取编码方式
res = b"\xb2......"
encode_type = (chardet.detect(res)).get("encoidng")
str_res = res.decode(encode_type)
1062

被折叠的 条评论
为什么被折叠?