当前位置:网站首页><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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- [Cloud Native] DevOps (5): Integrating Harbor
- 110 MySQL interview questions and answers (continuously updated)
- 12个MySQL慢查询的原因分析
- centos7安装mysql5.7
- Duplicate entry 'XXX' for key 'XXX.PRIMARY' solution.
- 【云原生】DevOps(五):集成Harbor
- On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
- Unity Framework Design Series: How Unity Designs Network Frameworks
- MySQL事务(transaction) (有这篇就足够了..)
- 扫雷小游戏——C语言
猜你喜欢
HCIP第十天_BGP路由汇总实验
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
STM32——DMA
MySQL开窗函数
SQL row-column conversion
View source and switch mirrors in two ways: npm and nrm
On Governance and Innovation | 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum was successfully held
CentOS7 —— yum安装mysql
【R语言】【3】apply,tapply,lapply,sapply,mapply与par函数相关参数
ES 源码 API调用链路源码分析
随机推荐
Unity手机游戏性能优化系列:针对CPU端的性能调优
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)Solution
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
CentOS7 安装MySQL 图文详细教程
unity2d game
CentOS7 install MySQL graphic detailed tutorial
matlab abel变换图片处理
A complete introduction to JSqlParse of Sql parsing and conversion
ERP生产作业控制 金蝶
Centos7 install mysql5.7 steps (graphical version)
What are the advantages and disadvantages of Unity shader forge and the built-in shader graph?
打造基于ILRuntime热更新的组件化开发
mysql使用on duplicate key update批量更新数据
Temporal介绍
ABC D - Distinct Trio (Number of k-tuples
datagrip带参sql查询
Go中间件
MySQL事务隔离级别详解
TOGAF之架构标准规范(一)
Unity教程:URP渲染管线实战教程系列【1】