解决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

相关推荐
blammmp15 分钟前
Java:数据结构-枚举
java·开发语言·数据结构
何曾参静谧28 分钟前
「C/C++」C/C++ 指针篇 之 指针运算
c语言·开发语言·c++
暗黑起源喵33 分钟前
设计模式-工厂设计模式
java·开发语言·设计模式
WaaTong38 分钟前
Java反射
java·开发语言·反射
Troc_wangpeng39 分钟前
R language 关于二维平面直角坐标系的制作
开发语言·机器学习
努力的家伙是不讨厌的41 分钟前
解析json导出csv或者直接入库
开发语言·python·json
Envyᥫᩣ1 小时前
C#语言:从入门到精通
开发语言·c#
云空1 小时前
《Python 与 SQLite:强大的数据库组合》
数据库·python·sqlite
童先生1 小时前
Go 项目中实现类似 Java Shiro 的权限控制中间件?
开发语言·go
lulu_gh_yu1 小时前
数据结构之排序补充
c语言·开发语言·数据结构·c++·学习·算法·排序算法