当前位置:网站首页><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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- Heavyweight | The Open Atomic School Source Line activity was officially launched
- 【R语言】【3】apply,tapply,lapply,sapply,mapply与par函数相关参数
- Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]
- Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world
- STM32HAL库修改Hal_Delay为us级延时
- STM32 - DMA
- On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
- 扫雷小游戏——C语言
- MySQL window function
- Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
猜你喜欢
随机推荐
Doris学习笔记之监控
Industry landing presents new progress | 2022 OpenAtom Global Open Source Summit OpenAtom OpenHarmony sub-forum was successfully held
unity2d game
MySQL optimization slow log query
MySQL transaction (transaction) (this is enough..)
Interview | Cheng Li, CTO of Alibaba: Cloud + open source together form a credible foundation for the digital world
【wpf】wpf中的那些模板之深度解析
matlab abel变换图片处理
Temporal客户端模型
Apache DButils使用注意事项--with modifiers “public“
CentOS7 安装MySQL 图文详细教程
DVWA之SQL注入
ERP Production Operation Control Kingdee
Unity手机游戏性能优化系列:针对CPU端的性能调优
HCIP Day 10_BGP Route Summary Experiment
Multiple table query of sql statement
datagrip带参sql查询
C Implementation of Simple Network File Copy
centos7安装mysql5.7步骤(图解版)
PCL calculates the point cloud coordinate maximum and its index