`DeprecationWarning` thrown when calling websockets (17.1 and later)

未關閉 適合新手
#4,337 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
65/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
python

研究方向

從 openai/lib/_websocket.py 開始,回溯顯示 connection.recv(decode=False) 會觸發 websockets 同步用戶端中的警告。追蹤連線的建立位置,並檢視 websockets 17.1 及更新版本相關的相依性相容性。使用高於 17.0 的 websockets 版本重現問題,接著確認 WebSocket 測試通過,且沒有棄用警告或連線失敗。

由索引模型根據 Issue 內容生成。

描述

bug
Confirm this is an issue with the Python library and not an underlying OpenAI API
  • This is an issue with the Python library
Describe the bug

While building openai @ 3.60.0 for nixpkgs, we receive a deprecation warning that leads to websocket failures.

Example:

DEBUG    openai.resources.responses.responses:_websocket_connection.py:73 Connecting to WebSocket API
_ test_raw_connection_invalid_stream_id_cannot_bind[next-completed-bad_id2-sync] _
[gw17] linux -- Python 3.14.10 /nix/store/y40f5jb7l7kgf4l118qzg3k14xy86f9i-python3-3.14.10/bin/python3.14
tests/lib/responses/test_websocket_accumulator.py:825: in test_raw_connection_invalid_stream_id_cannot_bind
    events = [connection.recv() for _ in range(4)]
              ^^^^^^^^^^^^^^^^^
/nix/store/9kpjx34y6sn473pnnbrzlcip53bp56r9-python3.14-openai-3.60.0/lib/python3.14/site-packages/openai/resources/responses/responses.py:4562: in recv
    event = self.parse_event(self.recv_bytes())
                             ^^^^^^^^^^^^^^^^^
/nix/store/9kpjx34y6sn473pnnbrzlcip53bp56r9-python3.14-openai-3.60.0/lib/python3.14/site-packages/openai/resources/responses/responses.py:4576: in recv_bytes
    message = _recv_bytes(self._connection)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/nix/store/9kpjx34y6sn473pnnbrzlcip53bp56r9-python3.14-openai-3.60.0/lib/python3.14/site-packages/openai/lib/_websocket.py:16: in _recv_bytes
    return connection.recv(decode=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/nix/store/d84spcb9cjynyja4prgnkn9snd6j6xk1-python3.14-websockets-17.4/lib/python3.14/site-packages/websockets/sync/connection.py:326: in recv
    self.maybe_raise_legacy_warning()
/nix/store/d84spcb9cjynyja4prgnkn9snd6j6xk1-python3.14-websockets-17.4/lib/python3.14/site-packages/websockets/sync/client.py:98: in maybe_raise_legacy_warning
    warnings.warn(  # deprecated in 17.1
E   DeprecationWarning: connect() must be used as a context manager: with connect(...) as websocket: ...; alternatively, use websocket = connect(..., legacy=True) to connect directly

Note: There is an known DDoS of in websockets < 17.4: https://github.com/python-websockets/websockets/security/advisories/GHSA-6m5v-9gmr-5665

To Reproduce

Build and test using websockets > 17.0

Code snippets

OS

NixOS (Linux), also MacOS

Python version

Python 3.14.10

Library version

openai 3.60.0

主要語言
Python
星號
32.2k
分支
5.8k
平均合併
12 小時 29 分鐘
30 天內合併 PR
112

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

openai/openai-python 的其他 Issue

查看 openai/openai-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。