当前位置:网站首页><urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍
<urlopen error [Errno 11001] getaddrinfo failed>的解决、isinstance()函数初略介绍
2022-07-31 05:08:00 【m0_67402125】
1,错误分析
爬虫实践时遇到了**<urlopen error [Errno 11001] getaddrinfo failed>**这个问题!
与我实践所要求的结果不一样(****我想得到的是这个网络超时)
百度了一下发现与我的情况都不一样。
链接网址问题,链接不存在或者打错了
网址单双引号问题
还有我的这种情况,就是单纯的没联网,当然就无法访问(被自个逗到了)
import urllib.request
import urllib.error
url='https://www.python.org/'
try:
#发送网络请求,设置时间为0.1秒
response=urllib.request.urlopen(url=url,timeout=0.1)
print(response.read().decode('utf-8'))
except urllib.error.URLError as error:
print(error)
联网后结果是:

顺便扩展一下:python内置函数
isinstance()的用法:用来判断错误类型是否一样,返回值为True或False,
语法:isinstance(实例对象,类名、基本类型或其组合)
类型相同则返回true,否则返回false
import urllib.request #导入urllib.request模块
import urllib.error #导入urllib.error模块
import socket #导入socket模块
url='https://www.python.org/' #请求地址
try:
#发送网络请求,设置时间为0.1秒
response=urllib.request.urlopen(url=url,timeout=0.1)
print(response.read().decode('utf-8')) #读取HTML代码并utf—8解码
except urllib.error.URLError as error: #处理异常
print(error) #输出错误
if isinstance(error.reason,socket.timeout): #判断是否为超时异常
print('当前任务已超时,即将执行下一任务!')

先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- HCIP第十天_BGP路由汇总实验
- 益智类游戏关卡设计:逆推法--巧解益智类游戏关卡设计
- Minio upload file ssl certificate is not trusted
- Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
- 【ORACLE Explain 详解】
- .NET-6.WinForm2.NanUI学习和总结
- Go中间件
- The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
- XSS靶场(三)prompt to win
- 2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
猜你喜欢

扫雷小游戏——C语言

Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world

On Governance and Innovation | 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum was successfully held

On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels

MySQL transaction (transaction) (this is enough..)
![[debug highlights] Expected input batch_size (1) to match target batch_size (0)](/img/b3/ff6ccc3cd307befad3bd07a9f4a956.png)
[debug highlights] Expected input batch_size (1) to match target batch_size (0)

Mysql应用安装后找不到my.ini文件

Lua,ILRuntime, HybridCLR(wolong)/huatuo热更新对比分析

Mysql application cannot find my.ini file after installation

matlab simulink欠驱动水面船舶航迹自抗扰控制研究
随机推荐
Gaussian distribution and its maximum likelihood estimation
sql语句-如何以一个表中的数据为条件据查询另一个表中的数据
Minio上传文件ssl证书不受信任
Unity资源管理系列:Unity 框架如何做好资源管理
限流的原理
Temporal对比Cadence
Centos7 install mysql5.7 steps (graphical version)
Tapdata 与 Apache Doris 完成兼容性互认证,共建新一代数据架构
Temporal介绍
SQL statement to range query time field
Sql解析转换之JSqlParse完整介绍
What are the advantages and disadvantages of Unity shader forge and the built-in shader graph?
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
The input input box displays the precision of two decimal places
MySQL常见面试题汇总(建议收藏!!!)
XSS shooting range (3) prompt to win
Visual studio shortcuts that improve efficiency, summary (updated from time to time)
Sun Wenlong, Secretary General of the Open Atom Open Source Foundation |
Apache DButils使用注意事项--with modifiers “public“
MySQL optimization: from ten seconds to three hundred milliseconds