簡體   English   中英

為什么會引發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.ServerTimeoutErrorasyncio.TimeoutError是不同類型的超時。

asyncio.TimeoutError是一種常規超時,由於許多不同的原因,從未存在的域開始或要讀取的數據太多,可能會發生這種情況。

aiohttp.ServerTimeoutError作為aiohttp.ServerTimeoutError中的搜索源代碼揭示一個地方使用 - 當與服務器建立連接時,但從套接字讀取的內容需要太長時間。 您還可以檢查aiohttp 測試以查看實際情況,您將獲得ServerTimeoutError

網絡請求的操作很復雜,並且可能在許多不同的地方出錯。 不要試圖全部了解它們(如果這不是你的目的)。 只要你只想做請求,抓住TimeoutError (因為ServerTimeoutError是一個子類 ),看看你是否應該改變timeout kwarg。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM