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

Đang mở Phù hợp với người mới
#4,337 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Bắt đầu với openai/lib/_websocket.py, nơi traceback cho thấy connection.recv(decode=False) dẫn đến cảnh báo trong ứng dụng khách đồng bộ của websockets. Theo dõi nơi kết nối được tạo và xem xét khả năng tương thích của các phụ thuộc quanh websockets 17.1 trở lên. Tái hiện vấn đề với websockets cao hơn 17.0, sau đó xác nhận các bài kiểm thử WebSocket chạy thành công mà không có cảnh báo ngừng hỗ trợ hay lỗi kết nối.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
32.2k
Fork
5.8k
Merge trung bình
12 giờ 29 phút
Pull request đã merge (30 ngày)
112

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openai/openai-python

Tất cả issue của openai/openai-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.