当前位置: 首页 > news >正文

python3 爬虫相关学习8:python 的常见报错内容 汇总收集

目录

1 拼写错误  AttributeError: NameError: 等等 

2 类型错误 TypeError:  如字符串连接错误

TypeError: can only concatenate str (not “int“) to str

3 意外缩进  IndentationError: unexpected indent

4 找不到对应模块 ModuleNotFoundError:

5 语法错误 SyntaxError:

5.1 函数语法错误

5.2 字符串连接错误

SyntaxError: unterminated string literal


1 拼写错误  AttributeError: NameError: 等等 

  • AttributeError: module 'requests' has no attribute 'gat'. Did you mean: 'get'?
  • NameError: name 'priint' is not defined. Did you mean: 'print'?
  • python 还能给出修改意见

2 类型错误 TypeError:  如字符串连接错误

TypeError: can only concatenate str (not “int“) to str

  • 我原来代码有这么一句:
  • print ("本页返回状态码: "+res.status_code)
  • 运行会报错
  •  TypeError: can only concatenate str (not “int“) to str
  • 因为res.status_code 返回的是数字,只有字符串可以  "" + "" ,  所以用 str() 把 res.status_code 转化为string 就OK了
  • 修改为
  • print ("本页返回状态码: "+str(res.status_code))

   

3 意外缩进  IndentationError: unexpected indent

  • IndentationError: unexpected indent
  • 就是缩进不符合python 要求

4 找不到对应模块 ModuleNotFoundError:

  •  报错内容:  ModuleNotFoundError: No module named 'bs4'
  • 需要现安装模块后,才能引用

5 语法错误 SyntaxError:

5.1 函数语法错误

  • SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
  • python 还能给出修改意见
  • print ()

5.2 字符串连接错误

SyntaxError: unterminated string literal

  • SyntaxError: unterminated string literal
  • 未结束的字符串
  • 造成这种错误的原因其实就是你运行的字符串有多义性
  • 比如字符串的引号没有成对出现。
  • 比如 转义序列 使用不正确

报错例子

错误:print(‘I'm a student')

正确:print(‘Im a student')

错误:with open(loc1+str(page)+'\'+p_name, 'wb') as f:

正确:with open(loc1+str(page)+'\\'+p_name, 'wb') as f:


 

http://www.lryc.cn/news/92439.html

相关文章:

  • 活跃主机发现技术指南
  • 手机抓包fiddler配置及使用教程
  • STM32单片机(四)第一节:OLED调试工具
  • 自用的一些网址,码住!
  • 银行vr元宇宙全景虚拟展馆提供更加真实、立体、高效的数字资产交易场景
  • C++ 泛型编程 类型萃取器的运用
  • C++ String类(上篇)
  • nested exception is java.lang.NoClassDefFoundError
  • 科普:python怎么使用Pyinstaller模块打包成可执行文件
  • 企业级应用高性能可扩展架构设计
  • 【安全架构】
  • RabbitMq-高级
  • iOS App的打包和上架流程
  • Net6中遇到的一个很奇葩的问题
  • 2940. 花坛的最小改变次数
  • 安装源代码 QT 4.8.7
  • PINN学习与实验之拟合sin(x)
  • Java中进制转换的两种方法你知道吗?
  • Qemu搭建ARM Vexpress开发环境
  • JMM如何实现volatile写/读的内存语义
  • Smali的使用技巧:快速定位Android应用程序中的关键代码
  • 04_两种常见的网页反爬措施及应对方法
  • 安装docker环境,并制作docker镜像
  • MySQL数据库 – node使用
  • JAVA使用HTTP代码示例模板
  • elementui tree 支持虚拟滚动和treeLine (下)
  • 富人父母都教给孩子什么样的财富思维?
  • 国内比较火的报表工具测评——Smartbi电子表格软件和Finereport
  • 变电所运维云平台在电力系统中的应用
  • 【51单片机】AT24C20数据帧(I2C总线)