我对 Trio 和 Asks 都是新手,所以如果这是一个明显的错误,我深表歉意。
从 Trio 和 Asks 的文档中,我认为以下代码可以工作并允许我异步发出请求
import asks
import trio
async def test():
a = await asks.get('https://example.com')
trio.run(test)
但是它给了我很多错误并以
AttributeError: module 'trio' has no attribute 'MultiError'
结束
从文档中我假设这两个库是兼容的,但也许这是不正确的?
trio 的异常处理已更改,并且
trio.MultiError
已在新版本中删除。
import asks
import trio
async def test():
try:
a = await asks.get('https://example.com')
except (asyncio.CancelledError, BaseException) as exc:
print(f"An error occurred: {exc}")
trio.run(test)
只需使用
asyncio.CancelledError
或 BaseException
来捕获异常即可。