Python打开https链接报错:unable to get local issuer certificate

Python打开https链接报错:unable to get local issuer certificate 或安装Python3.10以上版本,需要openssl 1.1.1以上版本,会导致openssl 下面缺少证书,记录下安装方法

问题描述:

当使用urllib.urlopen打开一个 https 链接时抛出如下异常:

urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)>

原因:

本地证书不存在。

解决方法:

1、查看默认证书位置

import ssl
print(ssl.get_default_verify_paths())

执行结果:

DefaultVerifyPaths(cafile=None, capath=None, openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/Library/Frameworks/Python.framework/Versions/3.7/etc/openssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/Library/Frameworks/Python.framework/Versions/3.7/etc/openssl/certs')

由结果可见,ca文件不存在。

2、下载ca文件

http://curl.haxx.se/ca/cacert.pem

3、将下载的ca文件放到【openssl_cafile】指定位置,并创建【openssl_capath】指定目录

cd /Library/Frameworks/Python.framework/Versions/3.7/etc/openssl 
mkdir certs 
mv ~/Downloads/cacert.pem ./ 
mv cacert.pem cert.pem

再运行脚本就不会报错了。

posted @   阿风小子  阅读(2087)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
历史上的今天:
2023-02-23 网络通信TCP编程实例代码
2023-02-23 进程的守护进程的用法
2023-02-23 编写多进程编程
2023-02-23 usb免驱动摄像头实验
2023-02-23 Android学习之Service(1)--->Started方式
2023-02-23 我有一壶酒 Android学习之Service(1)--->BinderService方式
2023-02-23 Android----->多线程的实现Thread、IntentService的运用
点击右上角即可分享
微信分享提示