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

オープン 初心者向け
#4,337 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python

調査の方向性

openai/lib/_websocket.pyから始めます。トレースバックでは、connection.recv(decode=False)がwebsocketsの同期クライアントで警告に到達することが示されています。接続が作成される箇所をたどり、websockets 17.1以降に関する依存関係の互換性を確認します。websockets 17.0より新しいバージョンで再現し、その後、非推奨警告や接続失敗なしで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分
マージ済み PR(30日)
112

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/openai-python のほかの issue

openai/openai-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。