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

如何解决连接OpenAI GPT-3时的API连接与SSL证书错误?

可行解决方案

1. 绑定certifi证书路径给OpenAI请求

修改代码,强制OpenAI使用certifi提供的可信证书,同时修复Windows路径转义问题:

import certifi
import openai

openai.api_key = 'my_api_key'
# 指定SSL证书路径
openai.verify_ssl_certs = True
openai.ssl_ca_certs = certifi.where()

# 用原始字符串处理Windows路径,避免转义错误
with open(r"C:\Users\pythons_scripts\Corporate Governance1658287996.json", "rb") as f:
    response = openai.File.create(file=f, purpose="search")
print(response)

2. 临时关闭SSL验证(仅测试环境使用)

仅建议在本地测试时临时禁用SSL验证,生产环境绝对禁止此操作:

import openai

openai.api_key = 'my_api_key'
# 禁用SSL证书验证
openai.verify_ssl_certs = False

with open(r"C:\Users\pythons_scripts\Corporate Governance1658287996.json", "rb") as f:
    response = openai.File.create(file=f, purpose="search")
print(response)

3. 更新系统与Python证书

  • 更新certifi包到最新版本:
pip install --upgrade certifi
  • Windows系统可手动导入缺失的根证书:打开「Internet选项」→「内容」→「证书」,导入浏览器信任的根证书文件。

4. 配置代理(若网络需通过代理访问)

如果你的网络环境依赖代理,需给OpenAI客户端配置代理信息:

import openai

openai.api_key = 'my_api_key'
# 替换为实际代理地址
openai.proxy = {
    "http": "http://your-proxy-address:port",
    "https": "https://your-proxy-address:port"
}

with open(r"C:\Users\pythons_scripts\Corporate Governance1658287996.json", "rb") as f:
    response = openai.File.create(file=f, purpose="search")
print(response)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 00:27:20