当前位置:网站首页><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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
猜你喜欢

DVWA之SQL注入

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

Mysql application cannot find my.ini file after installation

MySQL事务隔离级别详解

MySQL database backup

Open Source Smart Future | 2022 OpenAtom Global Open Source Summit OpenAtom openEuler sub-forum was successfully held

ES 源码 API调用链路源码分析

12 reasons for MySQL slow query

MySQL优化之慢日志查询

扫雷小游戏——C语言
随机推荐
MySQL事务隔离级别详解
MySQL forgot password
【C语言】操作符详解
ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
TOGAF之架构标准规范(一)
DVWA靶场环境搭建
[Linear Neural Network] softmax regression
HCIP第十天_BGP路由汇总实验
DVWA installation tutorial (understand what you don't understand · in detail)
.NET-9. A mess of theoretical notes (concepts, ideas)
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
Unity资源管理系列:Unity 框架如何做好资源管理
限流的原理
mysql uses on duplicate key update to update data in batches
Numpy中np.meshgrid的简单用法示例
The input input box displays the precision of two decimal places
Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world
Workflow番外篇
SQL statement to range query time field
MySQL optimization slow log query