Python报错'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of dat
2022/7/9 1:21:32
本文主要是介绍Python报错'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of dat,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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
这篇关于Python报错'utf-8' codec can't decode bytes in position 1022-1023: unexpected end of dat的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门