小编Wei*_*914的帖子

Asnycio - RuntimeError:超时上下文管理器应该在任务未关闭的客户端会话中使用

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

我寻找了更多错误,但他们没有解决我的问题。我不太了解 await 函数或协程。我关闭了 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())
Run Code Online (Sandbox Code Playgroud)

我排除了它只是从api获取信息但出现错误-

RuntimeError: Timeout context manager should be used inside a task
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x000001774361A3C8>
Run Code Online (Sandbox Code Playgroud)

python asynchronous async-await python-asyncio aiohttp

3
推荐指数
1
解决办法
2593
查看次数