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

相关推荐
猎嘤一号10 分钟前
Windows11桌面解锁守护脚本
开发语言·python·opencv
蓝婷儿1 小时前
Python 数据建模与分析项目实战预备 Day 2 - 数据构建与字段解析(模拟简历结构化数据)
开发语言·python·机器学习
青衫客361 小时前
浅谈 Python 中的 yield——yield的返回值与send()的关系
开发语言·python
玩代码2 小时前
CompletableFuture 详解
java·开发语言·高并发·线程
hz_zhangrl2 小时前
CCF-GESP 等级考试 2025年6月认证C++三级真题解析
开发语言·c++·青少年编程·gesp·gesp2025年6月·c++三级
测试老哥2 小时前
Python+Selenium实现自动化测试
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例
人生在勤,不索何获-白大侠3 小时前
day21——特殊文件:XML、Properties、以及日志框架
xml·java·开发语言
Dxy12393102166 小时前
Python PDFplumber详解:从入门到精通的PDF处理指南
开发语言·python·pdf
EutoCool7 小时前
Qt:布局管理器Layout
开发语言·c++·windows·嵌入式硬件·qt·前端框架
Cyanto7 小时前
Spring注解IoC与JUnit整合实战
java·开发语言·spring·mybatis