我的奶牛
10.48M · 2026-03-26
certifi 是一个用于提供浏览器信任的CA(证书颁发机构)证书集合的 Python 库。 它可以帮助你:
requests)默认使用certifi来处理证书验证。certifi 广泛应用于以下实际场景:
certifi确保连接是加密且安全的。certifi为数据传输提供了信任链。certifi可以帮助建立正确的信任关系。pip install certifi
# 如果安装慢的话,推荐使用国内镜像源
pip install certifi -i
检查 certifi 模块提供的 CA 证书路径。
import certifi
import os
# 获取 certifi 提供的 CA 证书捆绑包的路径
ca_bundle_path = certifi.where()
# 打印证书路径
print(f"Certifi CA Bundle Path: {ca_bundle_path}")
# 判断该路径是否存在,如果存在则说明 certifi 正常工作
if os.path.exists(ca_bundle_path):
print("Certifi CA bundle file found. It's ready for secure connections.")
else:
print("Error: Certifi CA bundle file not found. Check your installation.")
# 这是一个简单的检查,实际使用中通常由 requests 等库自动调用
使用 PythonRun 在线运行这段代码,结果如下:
Certifi CA Bundle Path: /opt/python/certifi/cacert.pem
Certifi CA bundle file found. It's ready for secure connections.
使用 MermaidGo 绘制示例代码的流程图,结果如下: