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

Aperta Adatta ai principianti
#4,337 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Inizia da openai/lib/_websocket.py, dove il traceback mostra che connection.recv(decode=False) raggiunge l’avviso nel client sincrono di websockets. Traccia il punto in cui viene creata la connessione e verifica la compatibilità delle dipendenze con websockets 17.1 e versioni successive. Riproduci il problema con websockets superiore a 17.0, quindi conferma che i test WebSocket passano senza l’avviso di deprecazione o errori di connessione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Python
Stelle
32.2k
Fork
5.8k
Merge medio
12h 29m
PR unite (30g)
112

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openai/openai-python

Tutte le issue di openai/openai-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.