python-binance icon indicating copy to clipboard operation
python-binance copied to clipboard

'coroutine' object has no attribute 'tld' when start AsyncClient.create()

Open hoangdh5 opened this issue 3 years ago • 8 comments

Describe the bug I see that package was upgrade to new version with changing in the way to use web socket stream data.

I try to new the new with your guide but get this error 'coroutine' object has no attribute 'tld' when run AsyncClient.create() to create new connect to wss.

To Reproduce client = AsyncClient.create(api_key=API,api_secret=SEC,tld='com') bm = BinanceSocketManager(client)

Get error at second line:


AttributeError Traceback (most recent call last) in () 13 14 client = AsyncClient.create(api_key=API,api_secret=SEC,tld='com') ---> 15 bm = BinanceSocketManager(client) 16 # ts = bm.trade_socket('BNBBTC') 17 # # enter the context manager

/usr/local/lib/python3.7/dist-packages/binance/streams.py in init(self, client, loop, user_timeout) 256 257 """ --> 258 self.STREAM_URL = self.STREAM_URL.format(client.tld) 259 self.FSTREAM_URL = self.FSTREAM_URL.format(client.tld) 260 self.DSTREAM_URL = self.DSTREAM_URL.format(client.tld)

AttributeError: 'coroutine' object has no attribute 'tld'

Environment (please complete the following information):

  • Python version: [e.g. 3.5]
  • Virtual Env: Google Colab
  • python-binance version (1.0.4)

Hope u can fix it soon. Thanks alot

hoangdh5 avatar May 05 '21 11:05 hoangdh5

Hello,

Same problem for me with this upgrade, i rollback :(

It is possible to have a complete example, how to use websockets with this new version? What is the reason of this big change? future compatibility with Binance?

i search to convert "start_multiplex_socket" with this new version.

Regards.

TKR-US avatar May 05 '21 19:05 TKR-US

@hoangdh5 you need to await the AsyncClient.create call like

client = await AsyncClient.create(api_key=API,api_secret=SEC,tld='com')

There are examples in the websockets docs https://python-binance.readthedocs.io/en/latest/websockets.html

The change was to remove Tornado and autobahn legacy dependencies that caused pain for a lot of people trying to isntall it.

Instead using websockets and asyncio.

sammchardy avatar May 05 '21 22:05 sammchardy

Could u help to creat a full sample load data from this new.

I run sample but still get error:

------------------ Code ------------------ I just run the example from your guideline in colab: https://python-binance.readthedocs.io/en/latest/websockets.html

image

------------------ Error ------------------ RuntimeError Traceback (most recent call last) in () 20 21 loop = asyncio.get_event_loop() ---> 22 loop.run_until_complete(main())

1 frames /usr/lib/python3.7/asyncio/base_events.py in run_until_complete(self, future) 561 """ 562 self._check_closed() --> 563 self._check_runnung() 564 565 new_task = not futures.isfuture(future)

/usr/lib/python3.7/asyncio/base_events.py in _check_runnung(self) 521 def _check_runnung(self): 522 if self.is_running(): --> 523 raise RuntimeError('This event loop is already running') 524 if events._get_running_loop() is not None: 525 raise RuntimeError(

RuntimeError: This event loop is already running

hoangdh5 avatar May 06 '21 02:05 hoangdh5

Can you format your code a little better please.

sammchardy avatar May 06 '21 03:05 sammchardy

i also got the error ( RuntimeError 'This event loop is already running') when i use the Spyder IDE. When I run the sample from the terminal the error message no longer comes. Maybe this helps...

RnSchm avatar May 06 '21 05:05 RnSchm

Can you format your code a little better please.

Sorry i just get code from example.

hoangdh5 avatar May 06 '21 06:05 hoangdh5

Alternatively you can use the ThreadedWebsocketManager class which abstracts away any asyncio requirements for you.

some examples here in the docs https://python-binance.readthedocs.io/en/latest/websockets.html

sammchardy avatar May 11 '21 12:05 sammchardy

i also got the error ( RuntimeError 'This event loop is already running') when i use the Spyder IDE. When I run the sample from the terminal the error message no longer comes. Maybe this helps...

try add this, see if it helps

import nest_asyncio nest_asyncio.apply()

fengster123 avatar May 15 '21 14:05 fengster123