本来希望使用curl测试一下(来源:https://platform.openai.com/docs/api-reference/making-requests)
curl <https://api.openai.com/v1/chat/completions> \\
-H "Content-Type: application/json" \\
-H "Authorization: Bearer $OPENAI_API_KEY" \\
-d '{
"model": "gpt-4o-mini",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.7
}'
发现代理没有生效
尝试:先直接添加环境变量:
export http_proxy="<http://127.0.0.1:7890/>"
export https_proxy="<https://127.0.0.1:7890/>"
# 或者直接设置
export ALL_PROXY="socks5://127.0.0.1:7890"
发现报错:curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to 127.0.0.1:7890
(443 error:HTTPS连接中的TLS/SSL握手失败)
测试:本来直接curl <https://ipinfo.io
>(查看自己的IP地址数据)可以成功,结果export了代理反而SSL错误了
再尝试:发现macos系统自带curl命令,可能openssl库比较老,于是使用brew安装curl-openssl
,并更新curl
和openssl
库,which curl
查看是否使用了brew管理的curl
但是仍然报错:
curl: (35) TLS connect error: error:00000000:lib(0)::reason(0)
最终解决:在curl命令时,使用-x
参数手动指定代理(curl -x socks5://127.0.0.1:7890 <https://api.openai.com/v1/chat/completions
)>
学习