@Zo0meeer

Что означают различные ClientConnectorError в aiohttp?

У меня есть парсер, который вообще не блестит сложными запросами, всё сводится к:
async with session.get(url, proxy=proxy.url, proxy_auth=proxy.authentication) as response:
    pass

И в целом работает он идеально, целыми днями не возникает проблем, но вот только сегодня (да и в принципе пару раз в неделю такое случается) увидел в логах три разнообразных exception:
  1. [ERROR] from [app.parser][39] at [2022-08-06 02:49:15,547]: Cannot connect to host steamcommunity.com:443 ssl:default [Connection reset by peer]
    Traceback (most recent call last):
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
        return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
      File "uvloop/loop.pyx", line 2069, in create_connection
      File "uvloop/loop.pyx", line 2064, in uvloop.loop.Loop.create_connection
    ConnectionResetError: [Errno 104] Connection reset by peer
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/home/bot/app/logger.py", line 37, in wrapper_2
        return await function(*args, **kwargs)
      File "/home/bot/app/parser.py", line 58, in get_popular_items
        async with session.get(url, proxy=proxy.url, proxy_auth=proxy.authentication) as response:
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in __aenter__
        self._resp = await self._coro
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request
        conn = await self._connector.connect(
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect
        proto = await self._create_connection(req, traces, timeout)
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection
        _, proto = await self._create_direct_connection(req, traces, timeout)
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
        raise last_exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
        transp, proto = await self._wrap_create_connection(
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
        raise client_error(req.connection_key, exc) from exc
    aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host steamcommunity.com:443 ssl:default [Connection reset by peer]

  2. [ERROR] from [app.parser][39] at [2022-08-06 13:59:26,976]: Server disconnected
    Traceback (most recent call last):
      File "/home/bot/app/logger.py", line 37, in wrapper_2
        return await function(*args, **kwargs)
      File "/home/bot/app/parser.py", line 144, in get_item_orders
        async with session.get(url, proxy=proxy.url, proxy_auth=proxy.authentication) as response:
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in __aenter__
        self._resp = await self._coro
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/client.py", line 559, in _request
        await resp.start(conn)
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 898, in start
        message, payload = await protocol.read() # type: ignore[union-attr]
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/streams.py", line 616, in read
        await self._waiter
    aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

  3. [ERROR] from [app.parser][39] at [2022-08-06 13:57:23,561]: Cannot connect to host steamcommunity.com:443 ssl:default [Temporary failure in name resolution]
    Traceback (most recent call last):
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 1154, in _create_direct_connection
        hosts = await asyncio.shield(host_resolved)
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 1154, in _create_direct_connection
        hosts = await asyncio.shield(host_resolved)
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 1154, in _create_direct_connection
        hosts = await asyncio.shield(host_resolved)
      [Previous line repeated 10 more times]
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 867, in _resolve_host
        await event.wait()
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/locks.py", line 34, in wait
        raise self._exc
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 880, in _resolve_host
        addrs = await self._resolver.resolve(host, port, family=self._family)
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/resolver.py", line 33, in resolve
        infos = await self._loop.getaddrinfo(
      File "uvloop/loop.pyx", line 1514, in getaddrinfo
    socket.gaierror: [Errno -3] Temporary failure in name resolution
    
    The above exception was the direct cause of the following exception:
    
    Traceback (most recent call last):
      File "/home/bot/app/logger.py", line 37, in wrapper_2
        return await function(*args, **kwargs)
      File "/home/bot/app/parser.py", line 98, in get_item_identifier
        async with session.get(item.url) as response:
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/client.py", line 1138, in __aenter__
        self._resp = await self._coro
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request
        conn = await self._connector.connect(
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect
        proto = await self._create_connection(req, traces, timeout)
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection
        _, proto = await self._create_direct_connection(req, traces, timeout)
      File "/home/bot/venv/lib/python3.10/site-packages/aiohttp/connector.py", line 1166, in _create_direct_connection
        raise ClientConnectorError(req.connection_key, exc) from exc
    aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host steamcommunity.com:443 ssl:default [Temporary failure in name resolution]


На основании выше сказанного и того, что в Traceback я почти не наблюдаю своих функций, напрашивается вывод, что я не виноват. Но хочу убедиться в этом с помощью опытных хабровчан :)
Стоит обернуть код запроса в try-except или я что-то делаю не так?
  • Вопрос задан
  • 678 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы