首页 > 其他分享 >解决报错requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘xxx’, port=443): Max re

解决报错requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘xxx’, port=443): Max re

时间:2023-04-28 18:33:31浏览次数:51  
标签:HTTPSConnectionPool False ConnectionError url headers session 报错 requests respon

解决报错requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘xxx’, port=443): Max retries exceeded with url 使用requests时出错

解决报错requests.exceptions.ConnectionError: HTTPSConnectionPool(host=‘xxx’, port=443): Max retries exceeded with url 使用requests时出错

一、先检查一下自己的库中是否装了下面三个库

certifi、cryptography、pyOpenSSL



# 没有的话请依次安装
pip install certifi
pip install cryptography
pip install pyOpenSSL


二、请在网页请求中加入:verify=False

这个的含义是: requests设置移除SSL认证

response = requests.get(url, headers=headers,verify=False)
print(response)
# 但是可能会出现 InsecureRequestWarning 警告,
# 虽然不影响代码采集但是看着不舒服,可以加上下面两行:
import urllib3
urllib3.disable_warnings()

三、访问频繁

  1、在代码中加入延迟 time.sleep(3)
  2、更换IP
  3、更换使用随机的UA
  4、网络问题,更换网络或者使用手机流量

四、连接数过多

如果requests连接数很多,那么在请求中避免使用持久连接

可以在请求头headers中加入

headers = {'Connection': 'close'}

requests.adapters.DEFAULT_RETRIES = 5

五、可能出现的别的原因

1、设置session

import requests
session = requests.session()
...
response = session.get(url, headers=headers,verify=False)
print(response)

2、requests请求网页时可能会请求不到,重试,加入try…except…语句

try:
	response = session.get(url, headers=headers,verify=False)
except:
	response = session.get(url, headers=headers,verify=False)
print(response)

标签:HTTPSConnectionPool,False,ConnectionError,url,headers,session,报错,requests,respon
From: https://www.cnblogs.com/abldh12/p/17362931.html

相关文章

  • web.xml报错
    web.xml报错 Thecontentofelementtype"web-app"mustmatch"(icon?,display-name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-file-list?,err......
  • hive on spark报错
    Errorinquery:DetectedimplicitcartesianproductforLEFTOUTERjoinbetweenlogicalplansUnionJoinconditionismissingortrivial.Either:usetheCROSSJOINsyntaxtoallowcartesianproductsbetweentheserelations,or:enableimplicitcartesianpro......
  • 【TypeScript】document.body.style TS 报错 Cannot assign to 'style' because it is
    报错信息解决方法style对象提供了一个cssText属性,支持设置多种CSS样式:document.body.style.cssText=`width:${targetX}px;height:${targetY}px;transform:scale(${scaleRatio})translateX(-50%);left:50%`;还有其他方法也可以,参考下面的文章参考文章七爪源码:使用......
  • Python-运行库报错“ImportError: DLL load failed: 找不到指定的模块。”
    1.看到这个报错的一瞬间,以为是Pycharm有问题,加上公司的电脑,对于2020以后的版本的不适用,以为是Pycharm需要有改动。但是大费周章(不断安装卸载Pycharm)以后,依旧没有任何的改变。百度以后,说是第三方库的某个模块没有,让卸载三方库,重新安装。尝试过以后没有用。2.思考了两天,突然想到,这......
  • 控制台报错:[Vue warn]: Error in render: "TypeError: Cannot read properties of nu
    可能原因在调取接口获取返回值时,由于各种原因(参数错误、返回格式不规范等),导致接收返回时数据类型与初始值不同。data(){return{list:[]//原本是个数组对象}},methods:{getList(){letparams={}apiRequest(params).then(r......
  • Hadoop启动集群报错:Starting namenodes on [hadoop01] hadoop01: root@hadoop01: Per
    搭建三个hadoop集群的时候,master没有启动namenode和datanode,报错:Startingnamenodeson[hadoop01]hadoop01:root@hadoop01:Permissiondenied(publickey,gssapi-keyex,gssapi-with-mic,password).Startingdatanodeshadoop01:root@hadoop01:Permissiondenied(publicke......
  • PHP8编译安装报错make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
    make:***[ext/fileinfo/libmagic/apprentice.lo]错误1 解决:当配置PHP时出现make:***[ext/fileinfo/libmagic/apprentice.lo]Error1时是因为服务器内存不足1G只需要在配置命令中添加--disable-fileinfo即可......
  • ansible推送文件到目标主机时报错 UNREACHABLE! | Permission denied (publickey,gssa
    问题现象:[root@linlin]#ansibleall-mcopy-a'src=/etc/ansible/lin/test.txtdest=/home/'192.168.12.203|UNREACHABLE!=>{"changed":false,"msg":"Failedtoconnecttothehostviassh:[email protected]:Pe......
  • 关于el-checkbox-group 报错 length 未定义
     问题原因:页面在初始化的时候el-checkbox-group的v-model要绑定一个数组,但是我的在生命周期的created中才为其绑定数据,造成再渲染dom时绑定数据类型不对而报错解决办法:1.在视图渲染之前给该值赋值为空数组 解决办法:2在data中定义的数据初始化一个数组推荐使用方法2,方法1......
  • nacos报错:Nacos cluster is running with 1.X mode, can't accept gRPC request tempo
    nacos报错:Nacosclusterisrunningwith1.Xmode,can'tacceptgRPCrequesttemporarilynacos报错如下:Causedby:com.alibaba.nacos.api.exception.NacosException:Requestnacosserverfailed:atcom.alibaba.nacos.client.naming.remote.gprc.NamingGrp......