{"id":"f5391f6eff292dc1","repo":"encode/httpx","slug":"httpx-timeout-must-either-include-a-default-or-se","errorCode":null,"errorMessage":"httpx.Timeout must either include a default, or set all four parameters explicitly.","messagePattern":"httpx\\.Timeout must either include a default, or set all four parameters explicitly\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"httpx/_config.py","lineNumber":123,"sourceCode":"        elif isinstance(timeout, tuple):\n            # Passed as a tuple.\n            self.connect = timeout[0]\n            self.read = timeout[1]\n            self.write = None if len(timeout) < 3 else timeout[2]\n            self.pool = None if len(timeout) < 4 else timeout[3]\n        elif not (\n            isinstance(connect, UnsetType)\n            or isinstance(read, UnsetType)\n            or isinstance(write, UnsetType)\n            or isinstance(pool, UnsetType)\n        ):\n            self.connect = connect\n            self.read = read\n            self.write = write\n            self.pool = pool\n        else:\n            if isinstance(timeout, UnsetType):\n                raise ValueError(\n                    \"httpx.Timeout must either include a default, or set all \"\n                    \"four parameters explicitly.\"\n                )\n            self.connect = timeout if isinstance(connect, UnsetType) else connect\n            self.read = timeout if isinstance(read, UnsetType) else read\n            self.write = timeout if isinstance(write, UnsetType) else write\n            self.pool = timeout if isinstance(pool, UnsetType) else pool\n\n    def as_dict(self) -> dict[str, float | None]:\n        return {\n            \"connect\": self.connect,\n            \"read\": self.read,\n            \"write\": self.write,\n            \"pool\": self.pool,\n        }\n\n    def __eq__(self, other: typing.Any) -> bool:\n        return (","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_config.py#L105-L141","documentation":"Raised as ValueError by Timeout.__init__ when no positional 'timeout' default is given AND at least one of connect/read/write/pool is left as UNSET. The constructor requires either a single default value or all four keyword params set explicitly; a partial specification with no default is ambiguous.","triggerScenarios":"Constructing httpx.Timeout with only some keyword args and no positional default, e.g. Timeout(connect=5.0) or Timeout(read=10.0, pool=5.0).","commonSituations":"Wanting to set just one timeout component without realizing a default is required; copying a partial config object; refactor that drops the default.","solutions":["Provide a default as the first arg: httpx.Timeout(5.0, connect=10.0).","Or set all four explicitly: httpx.Timeout(connect=5, read=5, write=5, pool=5).","Use Timeout(None, connect=5.0) to set connect while leaving others unlimited."],"exampleFix":"// before\nhttpx.Timeout(connect=5.0)  # ValueError\n// after\nhttpx.Timeout(5.0, connect=10.0)  # 10s connect, 5s elsewhere","handlingStrategy":"validation","validationCode":"import httpx\nfrom httpx._config import UnsetType, UNSET\n\ndef timeout_valid(timeout, *, connect=UNSET, read=UNSET, write=UNSET, pool=UNSET) -> bool:\n    all_set = not any(isinstance(x, UnsetType) for x in (connect, read, write, pool))\n    return not isinstance(timeout, UnsetType) or all_set\n\nassert timeout_valid(timeout, connect=connect, read=read, write=write, pool=pool), \\\n    \"provide a default or all four of connect/read/write/pool\"","typeGuard":"from httpx._config import UnsetType\n\ndef timeout_fully_specified(connect, read, write, pool) -> bool:\n    return not any(isinstance(x, UnsetType) for x in (connect, read, write, pool))","tryCatchPattern":"try:\n    t = httpx.Timeout(connect=5.0)\nexcept ValueError:\n    t = httpx.Timeout(5.0, connect=10.0)  # supply a default","preventionTips":["Always pass a positional default to Timeout, e.g. Timeout(5.0, connect=...).","If you must set individual fields, set all four explicitly.","Validate timeout config at app startup, not in request hot paths."],"tags":["timeout","config"],"analyzedSha":"b5addb64f0161ff6bfe94c124ef76f6a1fba5254","analyzedAt":"2026-08-04T19:32:56.768Z","schemaVersion":2}