# Buggy code
async def resolve(
    self, host: str, port: int = 0, family: int = socket.AF_INET
) -> List[Dict[str, Any]]:
    infos = await self._loop.getaddrinfo(
        host, port, type=socket.SOCK_STREAM, family=family
    )

    hosts = []
    for family, _, proto, _, address in infos:
        if family == socket.AF_INET6 and address[3]:  # type: ignore
            # This is essential for link-local IPv6 addresses.
            # LL IPv6 is a VERY rare case. Strictly speaking, we should use
            # getnameinfo() unconditionally, but performance makes sense.
            host, _port = socket.getnameinfo(
                address, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV
            )
            port = int(_port)
        else:
            host, port = address[:2]
        hosts.append(
            {
                "hostname": host,
                "host": host,
                "port": port,
                "family": family,
                "proto": proto,
                "flags": socket.AI_NUMERICHOST | socket.AI_NUMERICSERV,
            }
        )

    return hosts


# Traceback (ssl.SSLCertVerificationError)
Traceback (most recent call last):
File "/home/lilydjwg/tmpfs/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 946, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
File "/usr/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
transport, protocol = await self._create_connection_transport(
File "/usr/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport                                              await waiter                                                                                                                          File "/usr/lib/python3.8/asyncio/sslproto.py", line 529, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File "/usr/lib/python3.8/asyncio/sslproto.py", line 189, in feed_ssldata
self._sslobj.do_handshake()
File "/usr/lib/python3.8/ssl.py", line 944, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP address mismatch, certificate is not valid
for '151.101.128.223'. (_ssl.c:1124)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "t.py", line 12, in <module>
asyncio.run(main())
File "/usr/lib/python3.8/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
return future.result()
File "t.py", line 8, in main
r = await session.get('https://pypi.org/')
File "/home/lilydjwg/tmpfs/venv/lib/python3.8/site-packages/aiohttp/client.py", line 490, in _request
conn = await self._connector.connect(
File "/home/lilydjwg/tmpfs/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 528, in connect
proto = await self._create_connection(req, traces, timeout)
File "/home/lilydjwg/tmpfs/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 868, in _create_connection
_, proto = await self._create_direct_connection(
File "/home/lilydjwg/tmpfs/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 1023, in _create_direct_connection
raise last_exc
File "/home/lilydjwg/tmpfs/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 999, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/home/lilydjwg/tmpfs/venv/lib/python3.8/site-packages/aiohttp/connector.py", line 948, in _wrap_create_connection
raise ClientConnectorCertificateError(
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host pypi.org:443 ssl:True [SSLCertVerificationError: (1, "[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP address mismatch, certificate is not valid for '151.101.128.223'. (_ssl.c:1124)")]

# Fixed code
async def resolve(
    self, hostname: str, port: int = 0, family: int = socket.AF_INET
) -> List[Dict[str, Any]]:
    infos = await self._loop.getaddrinfo(
        hostname, port, type=socket.SOCK_STREAM, family=family
    )

    hosts = []
    for family, _, proto, _, address in infos:
        if family == socket.AF_INET6 and address[3]:  # type: ignore
            # This is essential for link-local IPv6 addresses.
            # LL IPv6 is a VERY rare case. Strictly speaking, we should use
            # getnameinfo() unconditionally, but performance makes sense.
            host, _port = socket.getnameinfo(
                address, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV
            )
            port = int(_port)
        else:
            host, port = address[:2]
        hosts.append(
            {
                "hostname": hostname,
                "host": host,
                "port": port,
                "family": family,
                "proto": proto,
                "flags": socket.AI_NUMERICHOST | socket.AI_NUMERICSERV,
            }
        )

    return hosts