【python】ssl.SSLCertVerificationError

这篇具有很好参考价值的文章主要介绍了【python】ssl.SSLCertVerificationError。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1.报错信息

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1007)

C:\Users\na.chen\AppData\Local\Microsoft\WindowsApps\python3.10.exe C:\Users\na.chen\PycharmProjects\python_for_work\auto_click\for_jenkins_CN\build_now.py 
Traceback (most recent call last):
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\util\ssl_.py", line 449, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\util\ssl_.py", line 493, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 513, in wrap_socket
    return self.sslsocket_class._create(
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 1071, in _create
    self.do_handshake()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\lib\ssl.py", line 1342, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1007)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='blog.csdn.net', port=443): Max retries exceeded with url: /cun_king (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1007)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\na.chen\PycharmProjects\python_for_work\auto_click\for_jenkins_CN\build_now.py", line 21, in <module>
    strhtml = requests.get(url=url, headers=headers)  # Get方式获取网页数据
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='blog.csdn.net', port=443): Max retries exceeded with url: /cun_king (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1007)')))

Process finished with exit code 1

2.解决办法

在  requests.get() 函数里加 verify=False ,这样客户端就不会校验 SSL;文章来源地址https://www.toymoban.com/news/detail-820772.html

3.正确可执行代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 5/8/2023 3:32 PM
# @Author  : Nora
# @File    : build_now.py
# @Description : to show 点击量; 


import requests
from bs4 import BeautifulSoup
import ssl
import urllib


url = 'https://blog.csdn.net/cun_king'
# context = ssl._create_unverified_context()
# data = urllib.request.urlopen(url, context=context).read().decode('utf-8')

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
                         'Chrome/112.0.0.0 Safari/537.36'}
strhtml = requests.get(url=url, headers=headers,verify=False)  # Get方式获取网页数据
soup = BeautifulSoup(strhtml.text, 'lxml')
info = soup.select('#userSkin > div.user-profile-head > '
                   'div.user-profile-head-info > div.user-profile-head-info-t > div > div.user-profile-head-info-rr > div.user-profile-head-info-r-c > ul > '
                   'li:nth-child(1) > span > span > span > div.user-profile-statistics-num')
print("访问量:" + info[0].get_text())

4.结果展示:

C:\Users\na.chen\AppData\Local\Microsoft\WindowsApps\python3.10.exe C:\Users\na.chen\PycharmProjects\python_for_work\auto_click\for_jenkins_CN\build_now.py 
C:\Users\na.chen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'blog.csdn.net'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
访问量:144,796

Process finished with exit code 0

到了这里,关于【python】ssl.SSLCertVerificationError的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • GET请求带参数,请求后出现Caused by SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] [已解决]

    运行python,发送get请求,请求后出现requests.exceptions.SSLError:  (Caused by SSLError(SSLCertVerificationError(1, \\\'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)\\\'))) 解决办法: import urllib3 导包后,将urllib3.disable_warnings()写在首部 添加参数 verify=False 到请

    2024年02月12日
    浏览(69)
  • 【python】ssl.SSLCertVerificationError

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1007) 在  requests.get() 函数里加 verify=False ,这样客户端就不会校验 SSL;

    2024年01月24日
    浏览(37)
  • python爬虫ssl.SSLCertVerificationError解决办法

    python当使用requests.get获取https链接时,提示如下错误: ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056) 方法一: 最方便的手段是直接设置不验证,即: 方法二: 全局取消证书验证,简易方便,但对整个项目可能会

    2024年02月15日
    浏览(43)
  • 解决python报错[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:

    这个错误经常发生在在线下载代码, 模型文件或数据的时候。发生这个错误的原因是没有正确配置网络的证书相关的东西。 解决办法: 全局取消证书验证 参考: https://www.jianshu.com/p/7d8eee279e7d

    2024年02月10日
    浏览(41)
  • python安装第三方包异常【SSLEOFError】、[SSL: CERTIFICATE_VERIFY_FAILED]

    Could not fetch URL https://pypi.org/simple/ xxxx /: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=\\\'pypi.org\\\', port=443): Max retries exceeded with url: /simple/ xxxx l/ (Caused by SSLError(SSLEOFError(8, \\\'EOF occurred in violation of protocol (_ssl.c:852)\\\'),)) - skipping ERROR: Could not find a version that satisfies the requi

    2024年02月11日
    浏览(32)
  • python https urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

    Python 2.7.9 之后引入了一个新特性,当使用urllib.urlopen打开一个 https 链接时,会验证一次 SSL 证书。而当目标网站使用的是自签名的证书时就会抛出一个 urllib2.URLError: urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed 的错误 解决方案 1.局部处理方案 使用ssl创建未经验证的

    2024年02月05日
    浏览(42)
  • python3/pip3 SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

    mac os 电脑之前安装的是python3.9 , 现在升级到python3.10。 从python官网下载macos版本的python3.10 pkg。 双击安装。 程序使用aiohttp访问ebay 。 但是旧版本python执行程序时不会出现以上问题。猜是新python的环境没配置好。 进入python 3.10 的application安装路径。 执行证书安装命令: 安装

    2024年02月11日
    浏览(38)
  • 如何解决SSL: CERTIFICATE_VERIFY_FAILED

    \\\"SSL: CERTIFICATE_VERIFY_FAILED\\\"错误通常在使用Python的requests或urllib等库进行HTTPS请求时出现,它表明SSL证书验证失败。这可能是由于服务器证书无效、过期、自签名或缺失等原因所致。要解决此问题,可以尝试以下方法: 参考: http://www.howtouselinux.com/post/ssl-certificate_verify_failed-in-

    2024年02月16日
    浏览(45)
  • requests出现ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)解决方案

      大家好,我是爱编程的喵喵。双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为CSDN博客专家、人工智能领域优质创作者。喜欢通过博客创作

    2024年02月11日
    浏览(47)
  • repo init报error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

    在ubuntu执行repo init的时候报了repo init报error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed这种错误,解决方法是需要更新本地证书。问题现象以及解决方法如下所示: 安装证书 更新本地证书

    2024年02月05日
    浏览(47)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包