标签:ignore unexpected utf encoding 博客 decode 报错
Python执行是报错'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of data...
网上查相关解决办法,都是添加如下,不靠谱都没解决
#!/usr/bin/env python # coding=utf-8
最后的解决办法添加
if function(r, 'decode'): # r = r.decode('utf-8') r = r.decode('utf-8','ignore')
官方解释如下
help("".decode) decode(...) S.decode([encoding[,errors]]) -> object Decodes S using the codec registered for encoding. encoding defaults to the default encoding. errors may be given to set a different error handling scheme. Default is 'strict' meaning that encoding errors raise a UnicodeDecodeError. Other possible values are 'ignore' and 'replace' as well as any other name registered with codecs.register_error that is able to handle UnicodeDecodeErrors.
其他参数例子
#decode解码的四个参数 print((b"\x80abc").decode("utf-8","strict"))#出现错误 #加上(U+FFFD) print((b"\x80abc").decode("utf-8","replace")) #加反斜杠 print((b"\x80abc").decode("utf-8","backslashreplace")) #直接忽略 print((b"\x80abc").decode("utf-8","ignore"))
参考
(39条消息) pycharm UnicodeDecodeError: ‘utf-8‘ codec can‘t decode bytes in position 1022-1023: unexpected end o_hllyzms的博客-CSDN博客
https://blog.csdn.net/weixin_37989267/article/details/124190568
(39条消息) python utf-8报错_python处理一些乱码的中文文本时decode('utf-8')报错的处理_weixin_39801158的博客-CSDN博客
https://blog.csdn.net/weixin_39801158/article/details/110696370
(39条消息) python编解码,decode参数设置:ignore_Yang.Young的博客-CSDN博客_ignore python
https://blog.csdn.net/symayy/article/details/107250441
标签:ignore,unexpected,utf,encoding,博客,decode,报错 来源: https://www.cnblogs.com/paul8339/p/16458052.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。