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

Offen Anfängerfreundlich
#4,337 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
65/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
python

Rechercherichtung

Beginne mit openai/lib/_websocket.py, wo der Traceback zeigt, dass connection.recv(decode=False) die Warnung im synchronen websockets-Client auslöst. Verfolge, wo die Verbindung erstellt wird, und prüfe die Kompatibilität der Abhängigkeiten rund um websockets 17.1 und spätere Versionen. Reproduziere das Problem mit websockets über 17.0 und bestätige anschließend, dass die WebSocket-Tests ohne Deprecation-Warnung oder Verbindungsfehler bestehen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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

Vorherrschende Sprache
Python
Sterne
32.2k
Forks
5.8k
Ø Merge
12 Std. 29 Min.
Gemergte PRs (30 T.)
112

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus openai/openai-python

Alle Issues in openai/openai-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.