python常见报错-python 常见报错汇总

python官方文档:https://docs.python.org/zh-cn/3/tutorial/index.html

1.indentationerror:unindent does not match any outer indentation level

原因:没有对齐导致的,设置notepad:视图--》显示符号--》显示空格和制表符

参考:https://www.crifan.com/python_syntax_error_indentationerror/comment-page-1/

2.indentationerror expected indented block

原因:没有对齐导致的

3.UnicodeDecodeError:"utf-8" codec can"t decode byte xxx in position

一般这种情况出现得较多是在国标码(GBK)和utf8之间选择出现了问题,出现异常报错是由于设置了decode()方法的第二个参数errors为严格(strict)形式造成的,因为默认就是这个参数,将其更改为ignore等即可:

line.decode("utf-8","ignore")

4.TypeError: write() argument must be str, not bytes

文件打开方式有问题,用open("testfile.txt", "wb+")

5.urllib have no urlopen

python 用的时urllib.request.urlopen,所以要import urllib.request

6.TypeError: cannot use a string pattern on a bytes-like object

需要使用html_url=html_url.decode("utf-8")#python3 ;参考:https://blog.csdn.net/lxh199603/article/details/53192883

7.UnicodeDecodeError: "gbk" codec can"t decode byte 0xa1 in position 58: illegal multibyte sequence

解决办法1:

FILE_OBJECT= open("order.log","r", encoding="UTF-8")

解决方法2:

FILE_OBJECT= open("order.log","rb")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值