You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jupyter Notebook/Lab中运行requests出现SSL证书验证错误问题

解决步骤
  • 第一步:校验环境变量差异
    分别在Jupyter和iPython环境运行如下代码,对比输出结果:
import os
print(os.getenv('REQUESTS_CA_BUNDLE'))
print(os.getenv('CURL_CA_BUNDLE'))

如果Jupyter环境的两个变量输出和iPython不一致,在Jupyter运行请求代码前新增如下配置即可:

import os
import requests
os.environ['REQUESTS_CA_BUNDLE'] = requests.certs.where()
os.environ['CURL_CA_BUNDLE'] = requests.certs.where()
  • 第二步:显式指定证书路径发起请求
    如果环境变量一致,可在请求时手动指定证书路径规避问题:
requests.get("https://github.com", verify=requests.certs.where())
  • 第三步:临时关闭SSL校验(仅测试场景使用,不建议生产环境使用)
    如果仅做临时测试,可以直接关闭校验:
import urllib3
# 屏蔽不安全请求警告
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
requests.get("https://github.com", verify=False)
  • 补充排查:确认SSL库一致性
    分别在两个环境运行如下代码,对比SSL库版本和路径:
import ssl
print(ssl.OPENSSL_VERSION)
print(ssl.__file__)

如果输出不一致,重装Jupyter内核对应的SSL依赖即可解决。

内容的提问来源于stack exchange,提问作者Gozy4

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 12:09:03