python-binance
python-binance copied to clipboard
Not compatible with Python 3.10 (loop parameter for async.Queue has been removed).
Describe the bug
If I attempt to use something that starts the async socket (say, start_all_mark_price_socket()
), the moment it tries to do create a ReconnectingWebsocket
it will do self._queue = asyncio.Queue(loop=self._loop)
, which is now a removed parameter (it was previously deprecated).
To Reproduce
Just attempt to create a ReconnectingWebsocket
. It results in something similar to the following:
File "/app/bmweb/main/binance_integration.py", line 46, in _init_price_update
self.conn_key = self.binance_socket_manager.start_all_mark_price_socket(
File "/usr/local/lib/python3.10/site-packages/binance/streams.py", line 1329, in start_all_mark_price_socket
return self._start_async_socket(
File "/usr/local/lib/python3.10/site-packages/binance/streams.py", line 1195, in _start_async_socket
socket = getattr(self._bsm, socket_name)(**params)
File "/usr/local/lib/python3.10/site-packages/binance/streams.py", line 865, in all_mark_price_socket
return self._get_futures_socket(stream_name, futures_type=futures_type)
File "/usr/local/lib/python3.10/site-packages/binance/streams.py", line 385, in _get_futures_socket
return self._get_socket(path, stream_url, prefix, socket_type=socket_type)
File "/usr/local/lib/python3.10/site-packages/binance/streams.py", line 346, in _get_socket
self._conns[conn_id] = ReconnectingWebsocket(
File "/usr/local/lib/python3.10/site-packages/binance/streams.py", line 62, in __init__
self._queue = asyncio.Queue(loop=self._loop)
File "/usr/local/lib/python3.10/asyncio/queues.py", line 33, in __init__
super().__init__(loop=loop)
File "/usr/local/lib/python3.10/asyncio/mixins.py", line 17, in __init__
raise TypeError(
TypeError: As of 3.10, the *loop* parameter was removed from Queue() since it is no longer necessary
Expected behavior No error happens.
If we need the loop object, we should fetch it with the get_running_loop
function from the asyncio
module.
Environment (please complete the following information):
- Python version: 3.10.0
- Virtual Env: virtualenv
- OS: All
- python-binance version: 1.0.15
I believe this issue could be simply sovled by removing the loop argument:
# self._queue = asyncio.Queue(loop=self._loop)
self._queue = asyncio.Queue()
However, it seems only work with websockets
10.0+. Since the author of websockets
will fix the AWS issue in next release, we could wait until then.
I get the same fail & error with Python 3.10:
bsm = ThreadedWebsocketManager()
bsm.start()
bsm.start_symbol_ticker_socket(callback=callbackFunc, symbol="BTCUSDT")
I manually edited /local/lib/python3.10/site-packages/binance/streams.py to remove the (loop=self._loop) code as previous post - and no data stream is recieved by my app at all now.
Any workarounds / fixes?
@alcukcoder yes. Two options. The first one is obvious, wait and use python 3.9.
But the one you might be interested in is to replace the websockets
package with version 10.0+ instead of 9.1, then remove the loop parameter. I don't precisely know about your use case, but it worked in mine.
Thanks @maudemor. Updating websockets
stopped the error.
Will the next python-binance release fix this issue?
@alcukcoder Hello.
I am having same issues as you. I updated websockets
, deleted (loop=self._loop) and I get no stream. I also tried with (loop=self._loop) and I get same error.
Can you please tell me exactly what did you do.
Thanks
That is all I did, I just updated websockets to V10 and removed the (loop=self._loop) code.
You could try installing python3.9 and see if that works.
Hi, I am facing this issue, could someone please indicate how to upgrade websockets to a newer version? (I tried with pip but it still gets an older version)
TypeError: As of 3.10, the loop parameter was removed from Queue() since it is no longer necessary
MyCode: socket = bsm.trade_socket('BTCUSDT')
I updated websocket to newest version but still getting this error when i try defining my socket for trade_socket
Any word on an actual fix for this?
No luck yet. I have tried many ways to connect to the Binance web socket stream. They all result in an error for me still.
Sent with ProtonMail Secure Email.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Saturday, January 8th, 2022 at 9:45 AM, Jamie @.***> wrote:
Any word on an actual fix for this?
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
The error has been persistent still. Is there any non-hackish solution or update?
I could not figure out how to fix this on python 3.10. so i just ran everything on python 3.9 and everything works perfectly
Sent with ProtonMail Secure Email.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Saturday, January 22nd, 2022 at 7:48 AM, Tolga Üstünkök @.***> wrote:
The error has been persistent still. Is there any non-hackish solution or update?
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
I've made a PR that fixes this on my machine. I don't know if that parameter was ever used. It seems like it wasn't.
The web socket object will retain a reference to the async event queue, but it will no longer attempt to pass it to the Queue object.
-Fred
On 1/22/2022 6:44 PM, H2oPtic wrote:
I could not figure out how to fix this on python 3.10. so i just ran everything on python 3.9 and everything works perfectly
Sent with ProtonMail Secure Email.
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Saturday, January 22nd, 2022 at 7:48 AM, Tolga Üstünkök @.***> wrote:
The error has been persistent still. Is there any non-hackish solution or update?
— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>
— Reply to this email directly, view it on GitHub https://github.com/sammchardy/python-binance/issues/1058#issuecomment-1019378134, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGUCXMCUOCAG43CZNDCZU3UXM6N5ANCNFSM5F4ADPBA. You are receiving this because you are subscribed to this thread.Message ID: @.***>