解决python报错[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed:

bash 复制代码
>>> model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
Traceback (most recent call last):
  File "/myconda/envs/py37/lib/python3.7/urllib/request.py", line 1350, in do_open
    encode_chunked=req.has_header('Transfer-encoding'))
  File "/myconda/envs/py37/lib/python3.7/http/client.py", line 1277, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/myconda/envs/py37/lib/python3.7/http/client.py", line 1323, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/myconda/envs/py37/lib/python3.7/http/client.py", line 1272, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/myconda/envs/py37/lib/python3.7/http/client.py", line 1032, in _send_output
    self.send(msg)
  File "/myconda/envs/py37/lib/python3.7/http/client.py", line 972, in send
    self.connect()
  File "/myconda/envs/py37/lib/python3.7/http/client.py", line 1447, in connect
    server_hostname=server_hostname)
  File "/myconda/envs/py37/lib/python3.7/ssl.py", line 423, in wrap_socket
    session=session
  File "/myconda/envs/py37/lib/python3.7/ssl.py", line 870, in _create
    self.do_handshake()
  File "/myconda/envs/py37/lib/python3.7/ssl.py", line 1139, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1091)

这个错误经常发生在在线下载代码, 模型文件或数据的时候。发生这个错误的原因是没有正确配置网络的证书相关的东西。

解决办法: 全局取消证书验证

python 复制代码
import ssl
ssl._create_default_https_context = ssl._create_unverified_context

参考:

https://www.jianshu.com/p/7d8eee279e7d

相关推荐
Ratten11 分钟前
【Python 实战】---- 实现一个可选择、配置操作的批量文件上传工具(四)配置管理界面和逻辑实现
python
Ratten13 分钟前
【Python 实战】---- 实现一个可选择、配置操作的批量文件上传工具(五)打包成 exe 应用
python
跟橙姐学代码18 分钟前
写 Python 函数别再死抠参数了,这招让代码瞬间灵活
前端·python
CHEN5_0221 分钟前
【Java基础常见辨析】重载与重写,深拷贝与浅拷贝,抽象类与普通类
java·开发语言
Despacito0o39 分钟前
C语言基础:变量与进制详解
java·c语言·开发语言
nightunderblackcat1 小时前
进阶向:人物关系三元组,解锁人物关系网络的钥匙
开发语言·python·开源·php
站大爷IP1 小时前
Pandas与NumPy:Python数据处理的双剑合璧
python
站大爷IP1 小时前
Python枚举进化论:IntEnum与StrEnum的实战指南
python
甄超锋2 小时前
python sqlite3模块
jvm·数据库·python·测试工具·django·sqlite·flask
科大饭桶2 小时前
C++入门自学Day11-- String, Vector, List 复习
c语言·开发语言·数据结构·c++·容器