RustPython/RustPython · error · OSError
could not bind on any address out of %r
Error message
could not bind on any address out of %r
What it means
Raised by create_server when, after resolving the host(s), no socket could be bound at all - every bind attempt either failed or was skipped as EADDRNOTAVAIL (Lib/asyncio/base_events.py:1640). The message lists all candidate addresses that were tried. It usually means the requested address is not assigned to this machine - most often an IPv6 address on an IPv4-only host, or a hardcoded IP from another environment.
Source
Thrown at Lib/asyncio/base_events.py:1640
socket.IPV6_V6ONLY,
True)
try:
sock.bind(sa)
except OSError as err:
msg = ('error while attempting '
'to bind on address %r: %s'
% (sa, str(err).lower()))
if err.errno == errno.EADDRNOTAVAIL:
# Assume the family is not enabled (bpo-30945)
sockets.pop()
sock.close()
if self._debug:
logger.warning(msg)
continue
raise OSError(err.errno, msg) from None
if not sockets:
raise OSError('could not bind on any address out of %r'
% ([info[4] for info in infos],))
completed = True
finally:
if not completed:
for sock in sockets:
sock.close()
else:
if sock is None:
raise ValueError('Neither host/port nor sock were specified')
if sock.type != socket.SOCK_STREAM:
raise ValueError(f'A Stream Socket was expected, got {sock!r}')
sockets = [sock]
for sock in sockets:
sock.setblocking(False)
server = Server(self, sockets, protocol_factory,View on GitHub (pinned to aaeab4f754)
Solutions
- Bind all interfaces instead: host='' (or '0.0.0.0' / '::')
- Verify the address is assigned: ip addr show / ifconfig, or wait for the interface at startup
- Remove stale addresses from the host list; keep only addresses present on this host
Example fix
# before server = await loop.create_server(factory, '10.0.0.5', 8080) # after server = await loop.create_server(factory, '0.0.0.0', 8080) # or '' for all families
Defensive patterns
Strategy: fallback
Validate before calling
import socket
def local_ips():
ips = {'127.0.0.1', '::1'}
for target in ('8.8.8.8', '2001:4860:4860::8888'):
fam = socket.AF_INET6 if ':' in target else socket.AF_INET
s = socket.socket(fam, socket.SOCK_DGRAM)
try:
s.connect((target, 53))
ips.add(s.getsockname()[0])
except OSError:
pass
finally:
s.close()
return ips
if bind_host not in ('', '*', None) and bind_host not in local_ips():
raise ValueError(f'{bind_host!r} is not a local address') Try / catch
try:
server = await loop.create_server(factory, bind_host, port)
except OSError as e:
if 'could not bind on any address' in str(e):
logger.warning('%s not bindable; falling back to all interfaces', bind_host)
server = await loop.create_server(factory, '', port)
else:
raise Prevention
- Prefer '' (all interfaces) unless a specific address is required
- For IPv6 literals, verify the interface exists before binding
- Wait for interfaces during early boot instead of crashing
When it happens
Trigger: create_server(factory, host='::1', port=8080) on a system without IPv6; host=['10.0.0.5'] where 10.0.0.5 belongs to another machine; every address in a multi-host list failing.
Common situations: Hardcoded per-environment IPs drifting between machines; IPv6 enabled in config but disabled in containers/CI; network interfaces not up yet when the service starts during early boot.
Related errors
- error while attempting to bind on address %r: %s
- getaddrinfo({host!r}) returned empty list
- Neither host/port nor sock were specified
- 2nd arg must be a tuple
- server {self!r} is already being awaited on serve_forever()
AI-assisted analysis of RustPython/RustPython@aaeab4f754 (2026-08-17).
Data as JSON: /api/errors/1b4f3f4ab619205c.
Report an issue: GitHub.