sammchardy/python-binance

Error when close sockets - cannot found .fail_connection()

Closed this issue · 8 comments

Describe the bug
When try to close klines socket connection, exception is raised
AttributeError: 'ClientConnection' object has no attribute 'fail_connection'

To Reproduce
self.wsm is BinanceWebSocketManager

Stop working socket:
self.wsm.stop_socket(running_socket)

And
AttributeError: 'ClientConnection' object has no attribute 'fail_connection' is raised

from ReconnectingWebsocket:

    async def __aexit__(self, exc_type, exc_val, exc_tb):
        if self._exit_coro:
            await self._exit_coro(self._path)
        self.ws_state = WSListenerState.EXITING
        if self.ws:
            self.ws.fail_connection()

because self.ws is ClientConnection and does not have method fail_connection()
Only WebSocketCommonProtocol has that method

Expected behavior
Close socket

Environment (please complete the following information):

  • Python version: 3.13
  • OS: [Windows 10, also ubuntu]
  • python-binance version 1.0.22

Logs or Additional context
(aiohttp: 3.9.5)

Hello @Alfavisioner,

Thanks for reporting, today we will release a new version that fixes this issue.

Thank you!

Downgrade websockets can walkaround this:

pip uninstall websockets
pip install websockets==13.0

@yitech Correct but shortly we will release a version that works with every websockets version.

@yitech @Alfavisioner We just released a new version with the fix, can you please upgrade your python-binance and try again?

s.fail_connection(

Yes, the latest version of the Python-Binance library works successfully.
When a socket is canceled, the message 'CANCEL read_loop' is shown without any errors.

However, I am experiencing other issues when using the latest version of CCXT (4.4.34) instead:

CCXT, in combination with Aiohttp 3.11.8, cannot start a socket for Binance.
CCXT, in combination with Aiohttp 3.10.8, cannot start the socket on the first attempt but succeeds on the second attempt.
CCXT, in combination with Aiohttp 3.9.5, works well.

@Alfavisioner

When a socket is canceled, the message 'CANCEL read_loop' is shown without any errors.

I think this is just a warning but we will check it

However, I am experiencing other issues when using the latest version of CCXT (4.4.34) instead:

@Alfavisioner Can you please open an issue there?

CANCEL read_loop

Yes, it is logging in the code:

    if self._handle_read_loop:
        self._log.error("CANCEL read_loop")
        await self._kill_read_loop()

Can you please open an issue there?
Yes, will open in CCXT