This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: asyncio.open_connection(local_addr=('localhost', port)) fails with TypeError: AF_INET address must be a pair (host, port)
Type: behavior Stage:
Components: asyncio Versions: Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, ecatmur2, yselivanov
Priority: normal Keywords:

Created on 2020-11-13 10:23 by ecatmur2, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg380874 - (view) Author: Ed Catmur (ecatmur2) Date: 2020-11-13 10:23
Context: CentOS 7.8.2003, Python 3.8 from SCL. localhost has IPv4 and IPv6 bindings, IPv6 first:
$ python -c "import socket;print(socket.getaddrinfo('localhost',0,type=socket.SOCK_STREAM))"
[(<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 0, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('', 0))]

import asyncio
async def main():
    await asyncio.open_connection('localhost', 9990, local_addr=('localhost', 9991))

Traceback (most recent call last):
  File "", line 4, in <module>
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/", line 43, in run
    return loop.run_until_complete(main)
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/", line 608, in run_until_complete
    return future.result()
  File "", line 3, in main
    await asyncio.open_connection('', 9990, local_addr=('localhost', 9991))
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/", line 52, in open_connection
    transport, _ = await loop.create_connection(
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/", line 1002, in create_connection
    sock = await self._connect_sock(
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/asyncio/", line 904, in _connect_sock
TypeError: AF_INET address must be a pair (host, port)

It looks like this has a similar root cause to issue 35302 - we should be filtering local addrinfos by family for valid combinations.
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86508
2020-11-13 10:23:37ecatmur2create