为什么 asyncio.TimeoutError 被引发?
Why asyncio.TimeoutError is raised?
我正在执行 aiohttp.ClientSession 实例的 request(),有时会引发 asyncio.TimeoutError。我认为在这种情况下必须提出 aiohttp.ServerTimeoutError,它源自 asyncio.TimeoutError,正如该文档所说:http://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ServerTimeoutError
为什么会这样?也许是因为我使用的是旧版本的 aiohttp? 2.3.8
UPD 这可能发生在像这样的非常简单的代码中
async def example_of_code():
session = aiohttp.ClientSession()
response = await session.request(
method='POST',
url='some_url',
params={'some': 'params'},
data={'some': 'data'},
headers={'some': 'headers'},
timeout=10
)
return await response.json()
aiohttp.ServerTimeoutError
和 asyncio.TimeoutError
是不同类型的超时。
asyncio.TimeoutError
是一般超时,可能由于许多不同的原因而发生,从不存在的域或太多数据无法读取开始。
aiohttp.ServerTimeoutError
在 aiohttp source code reveales is used in one place only - when connection with server established, but some reading from socket takes too long. You can also check aiohttp tests 中搜索以查看真实情况,在那里你得到 ServerTimeoutError
.
网络请求的操作比较复杂,可能会在很多不同的地方出错。不要试图全部理解它们(如果那不是你的目的)。只要你只想做请求,抓住 TimeoutError
(因为 ServerTimeoutError
是一个 subclass)看看你是否应该改变 timeout
kwarg.
我正在执行 aiohttp.ClientSession 实例的 request(),有时会引发 asyncio.TimeoutError。我认为在这种情况下必须提出 aiohttp.ServerTimeoutError,它源自 asyncio.TimeoutError,正如该文档所说:http://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ServerTimeoutError 为什么会这样?也许是因为我使用的是旧版本的 aiohttp? 2.3.8
UPD 这可能发生在像这样的非常简单的代码中
async def example_of_code():
session = aiohttp.ClientSession()
response = await session.request(
method='POST',
url='some_url',
params={'some': 'params'},
data={'some': 'data'},
headers={'some': 'headers'},
timeout=10
)
return await response.json()
aiohttp.ServerTimeoutError
和 asyncio.TimeoutError
是不同类型的超时。
asyncio.TimeoutError
是一般超时,可能由于许多不同的原因而发生,从不存在的域或太多数据无法读取开始。
aiohttp.ServerTimeoutError
在 aiohttp source code reveales is used in one place only - when connection with server established, but some reading from socket takes too long. You can also check aiohttp tests 中搜索以查看真实情况,在那里你得到 ServerTimeoutError
.
网络请求的操作比较复杂,可能会在很多不同的地方出错。不要试图全部理解它们(如果那不是你的目的)。只要你只想做请求,抓住 TimeoutError
(因为 ServerTimeoutError
是一个 subclass)看看你是否应该改变 timeout
kwarg.