{"record":{"id":"37efea5fa995dcab","repo":"python/cpython","slug":"host-and-port-was-not-specified-and-no-sock-specif","errorCode":null,"errorMessage":"host and port was not specified and no sock specified","messagePattern":"host and port was not specified and no sock specified","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Lib/asyncio/base_events.py","lineNumber":1192,"sourceCode":"                        raise exceptions[0]\n                    elif exceptions:\n                        # If they all have the same str(), raise one.\n                        model = str(exceptions[0])\n                        if all(str(exc) == model for exc in exceptions):\n                            raise exceptions[0]\n                        # Raise a combined exception so the user can see all\n                        # the various error messages.\n                        raise OSError('Multiple exceptions: {}'.format(\n                            ', '.join(str(exc) for exc in exceptions)))\n                    else:\n                        # No exceptions were collected, raise a timeout error\n                        raise TimeoutError('create_connection failed')\n                finally:\n                    exceptions = None\n\n        else:\n            if sock is None:\n                raise ValueError(\n                    'host and port was not specified and no sock specified')\n            if sock.type != socket.SOCK_STREAM:\n                # We allow AF_INET, AF_INET6, AF_UNIX as long as they\n                # are SOCK_STREAM.\n                # We support passing AF_UNIX sockets even though we have\n                # a dedicated API for that: create_unix_connection.\n                # Disallowing AF_UNIX in this method, breaks backwards\n                # compatibility.\n                raise ValueError(\n                    f'A Stream Socket was expected, got {sock!r}')\n\n        transport, protocol = await self._create_connection_transport(\n            sock, protocol_factory, ssl, server_hostname,\n            ssl_handshake_timeout=ssl_handshake_timeout,\n            ssl_shutdown_timeout=ssl_shutdown_timeout)\n        if self._debug:\n            # Get the socket from the transport because SSL transport closes\n            # the old socket and creates a new SSL socket","sourceCodeStart":1174,"sourceCodeEnd":1210,"githubUrl":"https://github.com/python/cpython/blob/bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6/Lib/asyncio/base_events.py#L1174-L1210","documentation":"Raised by create_connection when neither host/port nor sock was provided. The method needs either an address to resolve-and-dial or an already-connected socket to adopt; with both absent there is nothing to connect, so it raises ValueError immediately.","triggerScenarios":"loop.create_connection(proto) or loop.create_connection(proto, None, None) — host and port default to None and no sock was passed. Common when host/port come from config and both resolve to None/empty.","commonSituations":"Config-driven clients where required host/port keys are missing and code passes the values through unchecked; parsers that strip values and yield None; test scaffolding that forgot to populate the target.","solutions":["Validate configuration before connecting: assert host and port are set (and port is an int).","Pass sock=... if your intent is to adopt an existing connected socket.","Fail fast at config load with a clear message instead of deep inside asyncio."],"exampleFix":"// before\nhost = cfg.get('host')  # missing -> None\nawait loop.create_connection(proto, host, cfg.get('port'))\n\n// after\nhost, port = cfg['host'], int(cfg['port'])\nif not host or not port:\n    raise ConfigError('host and port are required')\nawait loop.create_connection(proto, host, port)","handlingStrategy":"validation","validationCode":"if not host and sock is None:\n    raise ConfigError('create_connection requires host/port or sock')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate required connection config at load time, not inside the network layer.","Type connection targets as a union (host/port pair vs socket) so 'neither' is unrepresentable.","Add assertions in tests that config parsing always yields a usable target."],"tags":["asyncio","network","validation","configuration"],"backgroundTag":null,"analyzedSha":"bc6749cc3b5ae4a5e88a6cc2d5b3bebbe354eae6","analyzedAt":"2026-08-14T22:01:13.976Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}