V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
HUZHUANGZHUANG
V2EX  ›  问与答

Python 调用 openai SDK 进行对话,一直提示有 SSL 的问题,请问大佬们是怎么解决的?

  •  
  •   HUZHUANGZHUANG · 184 天前 · 399 次点击
    这是一个创建于 184 天前的主题,其中的信息可能已经有所发展或是发生改变。
    这里也有一拨人反馈有这个问题

    https://community.openai.com/t/ssl-certificate-verify-failed/32442/72?page=2

    我用: https://community.openai.com/t/ssl-certificate-verify-failed/32442/72?page=2 。这里面人提到的方法去解决,全都失败。比如:把网站证书,添加到运行环境中来

    另外:wildcard 提供的每天 2000 次的接口转发服务到底能不能用?虽然看到了消耗次数,但是请求结果还是一直报错 SSl 错误

    Traceback (most recent call last):
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions
    yield
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpx/_transports/default.py", line 233, in handle_request
    resp = self._pool.handle_request(req)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 216, in handle_request
    raise exc from None
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpcore/_sync/connection_pool.py", line 196, in handle_request
    response = connection.handle_request(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 99, in handle_request
    raise exc
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 76, in handle_request
    stream = self._connect(request)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpcore/_sync/connection.py", line 154, in _connect
    stream = stream.start_tls(**kwargs)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpcore/_backends/sync.py", line 168, in start_tls
    raise exc
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    raise to_exc(exc) from exc
    httpcore.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_base_client.py", line 952, in _request
    response = self._client.send(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpx/_client.py", line 914, in send
    response = self._send_handling_auth(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpx/_client.py", line 942, in _send_handling_auth
    response = self._send_handling_redirects(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
    response = self._send_single_request(request)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpx/_client.py", line 1015, in _send_single_request
    response = transport.handle_request(request)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpx/_transports/default.py", line 233, in handle_request
    resp = self._pool.handle_request(req)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
    httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
    File "/home/ljk/code/crawling_wechat_data/ChatGPT/chat_with_gpt.py", line 62, in <module>
    stream_gpt_responses1(api_key, base_url)
    File "/home/ljk/code/crawling_wechat_data/ChatGPT/chat_with_gpt.py", line 38, in stream_gpt_responses1
    stream = client.chat.completions.create(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_utils/_utils.py", line 277, in wrapper
    return func(*args, **kwargs)
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/resources/chat/completions.py", line 590, in create
    return self._post(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_base_client.py", line 1240, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_base_client.py", line 921, in request
    return self._request(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_base_client.py", line 976, in _request
    return self._retry_request(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_base_client.py", line 1053, in _retry_request
    return self._request(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_base_client.py", line 976, in _request
    return self._retry_request(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_base_client.py", line 1053, in _retry_request
    return self._request(
    File "/home/ljk/anaconda3/envs/wechat_public_assistant/lib/python3.8/site-packages/openai/_base_client.py", line 986, in _request
    raise APIConnectionError(request=request) from err
    openai.APIConnectionError: Connection error.
    第 1 条附言  ·  184 天前
    回答问题后,请留下微信。我测试过后,会加微信发给红包表示感谢。谢谢
    第 2 条附言  ·  184 天前
    不用 SDK, 在 js 上换了常规的 http 请求方式,然后成功了
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   857 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 20ms · UTC 22:07 · PVG 06:07 · LAX 14:07 · JFK 17:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.