{"record":{"id":"efae08e4588d3c67","repo":"python/cpython","slug":"neither-host-port-nor-sock-were-specified","errorCode":null,"errorMessage":"Neither host/port nor sock were specified","messagePattern":"Neither host/port nor sock were specified","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":1666,"sourceCode":"                            sockets.pop()\n                            sock.close()\n                            if self._debug:\n                                logger.warning(msg)\n                            continue\n                        raise OSError(err.errno, msg) from None\n\n                if not sockets:\n                    raise OSError('could not bind on any address out of %r'\n                                  % ([info[4] for info in infos],))\n\n                completed = True\n            finally:\n                if not completed:\n                    for sock in sockets:\n                        sock.close()\n        else:\n            if sock is None:\n                raise ValueError('Neither host/port nor sock were specified')\n            if sock.type != socket.SOCK_STREAM:\n                raise ValueError(f'A Stream Socket was expected, got {sock!r}')\n            sockets = [sock]\n\n        for sock in sockets:\n            sock.setblocking(False)\n\n        server = Server(self, sockets, protocol_factory,\n                        ssl, backlog, ssl_handshake_timeout,\n                        ssl_shutdown_timeout)\n        if start_serving:\n            server._start_serving()\n            # Skip one loop iteration so that all 'loop.add_reader'\n            # go through.\n            await tasks.sleep(0)\n\n        if self._debug:\n            logger.info(\"%r is serving\", server)","sourceCodeStart":1648,"sourceCodeEnd":1684,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/base_events.py#L1648-L1684","documentation":"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.","triggerScenarios":"loop.create_server(factory) with all of host, port, sock defaulting to None; or passing host=None, port=None explicitly while forgetting sock.","commonSituations":"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.","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"],"exampleFix":"# before\nserver = await loop.create_server(factory)\n\n# after\nserver = await loop.create_server(factory, '127.0.0.1', 8080)","handlingStrategy":"validation","validationCode":"if sock is None and host is None and port is None:\n    raise ValueError('server endpoint required: pass (host, port) or sock=')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make host/port required fields in server config schemas with sensible defaults","Fail fast at config load when no endpoint is configured"],"tags":["asyncio","server","configuration","api-misuse"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}