为什么这不起作用:
try:
async with asyncio.wait_for(aiohttp.get(url), 2) as resp:
print(resp.text())
except asyncio.TimeoutError as e:
pass
给
async with asyncio.wait_for(aiohttp.get(url), 2) as resp:
AttributeError: __aexit__
据我了解,asyncio.wait_for()
将传递aiohttp.get()
具有__aenter__
and__aexit__
方法的 的未来(正如有效的事实所证明的那样async with aiohttp.get()
)。