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

相关推荐
小尧嵌入式16 分钟前
C++基础语法总结
开发语言·c++·stm32·单片机·嵌入式硬件·算法
white-persist17 分钟前
【攻防世界】reverse | IgniteMe 详细题解 WP
c语言·汇编·数据结构·c++·python·算法·网络安全
霍格沃兹测试开发学社-小明17 分钟前
AI来袭:自动化测试在智能实战中的华丽转身
运维·人工智能·python·测试工具·开源
@游子20 分钟前
Python学习笔记-Day2
开发语言·python
qq_3363139321 分钟前
java基础-集合进阶
java·开发语言·windows
222you23 分钟前
MybatisPlus常用注解
java·开发语言·spring
wanderist.24 分钟前
Linux使用经验——离线运行python脚本
linux·网络·python
九千七52633 分钟前
sklearn学习(3)数据降维
人工智能·python·学习·机器学习·sklearn
你的冰西瓜34 分钟前
C++20 新特性详解:相较于 C++17 的主要改进
开发语言·c++·stl·c++20
济宁雪人1 小时前
Java安全基础——JNI安全基础
java·开发语言