mac 运行python报 SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer

1、问题

python 报错:

File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1391, in https_open
return self.do_open(http.client.HTTPSConnection, req,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/urllib/request.py", line 1351, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)>

Process finished with exit code 1

2、分析

看起来即使使用 requests 库下载模型也无法解决 SSL 证书验证的问题。这可能是由于 macOS 系统本身对于 SSL 证书的配置和信任存在问题。

3、解决

import ssl

ssl._create_default_https_context = ssl._create_stdlib_context

这个修改可以解决之前 SSL 证书验证失败的问题。

通过设置 ssl._create_default_https_context = ssl._create_stdlib_context,绕过了 SSL 证书验证,从而可以正常下载和处理图像。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值