Asnycio - RuntimeError: Timeout context manager should be used inside a task Unclosed client session

Asnycio - RuntimeError: Timeout context manager should be used inside a task Unclosed client session

我正在尝试从我正在使用包装器的 api 获得一些响应。

我又找了一些错误,但他们没有解决我的问题。我不太了解等待函数或协程。我关闭了 is_asnyc,它起作用了,但我需要那个选项。所以我关不掉它。

import clashroyale, asyncio
token = "my token"
cr = clashroyale.official_api.Client(token=token, is_async=True)

async def top():
    p = await cr.get_top_players()
    return p

topplayers = asyncio.run(top())

我只是从 api 中获取信息,但出现错误-

RuntimeError: Timeout context manager should be used inside a task
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001774361A3C8>

尝试将客户端的初始化移动到异步方法中。它可能会尝试使用异步超时上下文管理器,并且由于您不在任务中,它会失败