有几个使用这里客户机而不是使用流行的oauth,authlib的基于requests的会话的示例
但是,在这些示例中,它们没有说明如何正确地打开和关闭异步httpx会话。请参阅https://www.python-httpx.org/async/
当我试图按建议使用它时,我会收到关于会话未被关闭的警告:
上的未关闭的0x000001B6444BFEB0>对象。详细信息请参见https://www.python-httpx.org/async/#opening-and-closing-clients
如果我打两次电话,我就会
RuntimeError:事件循环关闭
这对我来说完全有意义,因为authlib的文档中的示例没有为异步会话使用上下文管理器
发布于 2021-05-12 18:57:21
authlib的AsyncOAuth2Client继承了httpx的AsyncClient,所以您应该能够使用https://www.python-httpx.org/async/#opening-and-closing-clients提供的相同方法。
async with authlib.integrations.httpx_client.oauth2_client.AsyncOAuth2Client() as client:
...或者:
client = authlib.integrations.httpx_client.oauth2_client.AsyncOAuth2Client()
...
await client.aclose()应该允许您根据需要打开和关闭会话。
https://stackoverflow.com/questions/67441913
复制相似问题