当前位置:网站首页><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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- Explanation of
- 12 reasons for MySQL slow query
- [Detailed explanation of ORACLE Explain]
- View source and switch mirrors in two ways: npm and nrm
- On-line monitoring system for urban waterlogging and water accumulation in bridges and tunnels
- Temporal介绍
- Minio upload file ssl certificate is not trusted
- From scratch, a mirror to the end, a pure system builds a grasscutter (Grasscutter)
- 110道 MySQL面试题及答案 (持续更新)
- Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric
猜你喜欢

Mysql application cannot find my.ini file after installation

ERP Production Operation Control Kingdee

mysql存储过程

STM32HAL library modifies Hal_Delay to us-level delay

Minesweeper game - C language

Sql解析转换之JSqlParse完整介绍

Heavyweight | The Open Atomic School Source Line activity was officially launched

12 reasons for MySQL slow query
![2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。](/img/7f/130a9b733855a2bab07d26ffda2c49.png)
2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。

MySQL transaction (transaction) (this is enough..)
随机推荐
STM32——DMA
Temporal线上部署
【debug锦集】Expected input batch_size (1) to match target batch_size (0)
The monitoring of Doris study notes
sql语句之多表查询
Centos7 install mysql5.7 steps (graphical version)
Centos7 install mysql5.7
Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)Solution
高斯分布及其极大似然估计
DVWA安装教程(懂你的不懂·详细)
剑指offer专项突击版第15天
A complete introduction to JSqlParse of Sql parsing and conversion
限流的原理
Explanation of
Mysql应用安装后找不到my.ini文件
Minio上传文件ssl证书不受信任
【py脚本】批量二值化处理图像
Create componentized development based on ILRuntime hot update
Minesweeper game (written in c language)