python/cpython · error · ValueError
Neither host/port nor sock were specified
Error message
Neither host/port nor sock were specified
What it means
Raised by create_server() when neither host/port nor sock was provided — the method has no endpoint to listen on. create_server requires at least one binding source: an address pair or a pre-bound socket.
Source
Thrown at Lib/asyncio/base_events.py:1666
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,
ssl, backlog, ssl_handshake_timeout,
ssl_shutdown_timeout)
if start_serving:
server._start_serving()
# Skip one loop iteration so that all 'loop.add_reader'
# go through.
await tasks.sleep(0)
if self._debug:
logger.info("%r is serving", server)View on GitHub (pinned to bc6749cc3b)
Solutions
- Pass host and port, e.g. create_server(factory, '127.0.0.1', 8080)
- Or pass a pre-bound socket via sock=listener
- Use create_server(factory, None, port) to bind all interfaces on a port
Example fix
# before server = await loop.create_server(factory) # after server = await loop.create_server(factory, '127.0.0.1', 8080)
Defensive patterns
Strategy: validation
Validate before calling
if sock is None and host is None and port is None:
raise ValueError('server endpoint required: pass (host, port) or sock=') Prevention
- Make host/port required fields in server config schemas with sensible defaults
- Fail fast at config load when no endpoint is configured
When it happens
Trigger: loop.create_server(factory) with all of host, port, sock defaulting to None; or passing host=None, port=None explicitly while forgetting sock.
Common situations: Building a server from config where host/port keys are missing/None and no socket fallback is wired; refactoring away the sock= parameter and leaving nothing behind.
Related errors
- ssl argument must be an SSLContext or None
- Node can't be used without a value attribute.
- host and port was not specified and no sock specified
- socket modifier keyword arguments can not be used when sock
- getaddrinfo({host!r}) returned empty list
AI-assisted analysis of python/cpython@bc6749cc3b (2026-08-14).
Data as JSON: /api/errors/efae08e4588d3c67.
Report an issue: GitHub.