小编Max*_*wer的帖子

Python 3.10 中的 event_loops 问题

我尝试从 Binance Websocket 获取数据。使用 python 3.9 作为解释器它运行良好,但使用 3.10 它给了我错误:(

这是代码:

import asyncio
from binance import AsyncClient, BinanceSocketManager


async def main():
    client = await AsyncClient.create()
    bm = BinanceSocketManager(client)
    # start any sockets here, i.e a trade socket
    ts = bm.trade_socket('BNBBTC')
    # then start receiving messages
    async with ts as tscm:
        while True:
            res = await tscm.recv()
            print(res)


if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
Run Code Online (Sandbox Code Playgroud)

我使用 PyCharm 作为 IDE。

请问有人可以帮助我吗?

python websocket python-asyncio binance python-3.10

8
推荐指数
1
解决办法
4734
查看次数

标签 统计

binance ×1

python ×1

python-3.10 ×1

python-asyncio ×1

websocket ×1