WordPress网站建设宣传图片

Python requests 异常InsecureRequestWarning: Unverified HTTPS request is being made to host ‘***domain’. Adding certificate verification is strongly advised. See…解决

释放双眼,带上耳机,听听看~!

Python在使用requests模块的时候出现如下异常信息:

C:\Python\Python39\lib\site-packages\urllib3\connectionpool.py:1043: InsecureRequestWarning: Unverified HTTPS request is being made to host 'you request domain'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
Python requests 异常InsecureRequestWarning: Unverified HTTPS request is being made to host '***domain'. Adding certificate verification is strongly advised. See...解决 1

异常原因

出现这个异常通常情况下是我们关闭了SSL验证,请求时verify参数设置为了False,关于verify参数,具体你可以看:Python模块requests参数verify – SSL证书认证

解决方法

如果要关闭这个警告信息, 我们可以进行如下设置:

解决方法一:

import requests
import logging
logging.captureWarnings(True)

解决方法二:

from requests.packages.urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

详细信息

在pycharm中我们可以直接点击进入到警告信息触发的代码位置:

C:\Python\Python39\lib\site-packages\urllib3\connectionpool.py:1043:  
  if not conn.is_verified:
            warnings.warn(
                (
                    "Unverified HTTPS request is being made to host '%s'. "
                    "Adding certificate verification is strongly advised. See: "
                    "https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html"
                    "#ssl-warnings" % conn.host
                ),
                InsecureRequestWarning,
            )

大概意思就是我们在向主机发送未经验证的HTTPS请求, 强烈建议添加SSL证书验证(发出未经验证的 HTTPS 请求将会有安全风险,容易受到攻击 中间人 (MitM) 攻击。),详情可以参阅:https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings

Python requests 异常InsecureRequestWarning: Unverified HTTPS request is being made to host '***domain'. Adding certificate verification is strongly advised. See...解决 2

其他requests相关文章

Python模块requests参数verify – SSL证书认证

Python requests获取状态码

python模块requests参数stream

Python爬虫timeout以及retrying的使用

python requests请求之timeout参数

给TA打赏
共{{data.count}}人
人已打赏
Python RequestsPython与SEOPython爬虫SEO技巧精品资源

百度已收录404链接自动提取软件+使用教程-免费

2023-12-6 10:28:12

Python内置模块Python笔记

Python Excel常用操作库+使用笔记分享

2023-12-8 15:33:26

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
展开目录