bybit-exchange / pybit

Official Python3 API connector for Bybit's HTTP and WebSockets APIs.
Other
385 stars 129 forks source link

Websocket functionality broken on Python 3.12 #179

Closed aidro closed 3 months ago

aidro commented 9 months ago

Current OS: macOS 14.0 build(23A344).

While attempting to use this library I ran into an issue concerning the websocket functionality on macOS. It seems that Python 3.12 introduces some changes which causes the websocket connection to fail. When replicating this issue on a Windows based machine, the error was absent.

Consider the following example code:

from pybit.unified_trading import WebSocket
from time import sleep

ws = WebSocket(
    testnet=False,
    channel_type="linear",
)

def handle_message(message):
    print(message)

ws.orderbook_stream(50, "BTCUSDT", handle_message)

while True:
    sleep(1)

Steps to reproduce:

  1. Install Python 3.12
  2. Use pip with Python 3.12 to install the Pybit library
  3. Run example code. Code will throw an exception: File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pybit/_websocket_stream.py", line 169, in _connect raise websocket.WebSocketTimeoutException( websocket._exceptions.WebSocketTimeoutException: WebSocket Unified V5 (wss://stream.bybit.com/v5/public/linear) connection failed. Too many connection attempts. pybit will no longer try to reconnect.

Following the same steps to reproduce while using Python 3.11 instead of Python 3.12 results in the program functioning normally and returning the orderbook stream as expected.

stefanmsy commented 9 months ago

I just got similar error and it seems to be certificate issue. I ran "Install Certificates.command" in the python folder of that version and then the error went away. Not sure if it is the same issue though.

dmlinke commented 3 months ago

I also get the same error. Were you able to solve this issue?

issacnumb commented 3 months ago

i got same problem on CentOS, someone get me out ?

issacnumb commented 3 months ago

And i got the same problem when i try to solve it on Python 3.10/3.11 , now i believe this problem is not course by Python_Version

dextertd commented 3 months ago

You can refer to https://pypi.org/project/pybit/

Screenshot 2024-06-25 at 18 21 57