{"id":"b1a9f8d7d2865611","repo":"aio-libs/aiohttp","slug":"timeout-parameter-cannot-be-of-type-type-please","errorCode":null,"errorMessage":"timeout parameter cannot be of {type} type, please use 'timeout=ClientTimeout(...)'","messagePattern":"timeout parameter cannot be of (.+?) type, please use 'timeout=ClientTimeout\\(\\.\\.\\.\\)'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aiohttp/client.py","lineNumber":350,"sourceCode":"        else:\n            self._base_url = URL(base_url)\n            self._base_url_origin = self._base_url.origin()\n            assert self._base_url.absolute, \"Only absolute URLs are supported\"\n        if self._base_url is not None and not self._base_url.path.endswith(\"/\"):\n            raise ValueError(\"base_url must have a trailing '/'\")\n\n        if not isinstance(ssl, SSL_ALLOWED_TYPES):\n            raise TypeError(\n                \"ssl should be SSLContext, Fingerprint, or bool, \"\n                f\"got {ssl!r} instead.\"\n            )\n\n        loop = asyncio.get_running_loop()\n\n        if timeout is sentinel or timeout is None:\n            timeout = ClientTimeout()\n        if not isinstance(timeout, ClientTimeout):\n            raise ValueError(\n                f\"timeout parameter cannot be of {type(timeout)} type, \"\n                \"please use 'timeout=ClientTimeout(...)'\",\n            )\n        self._timeout = timeout\n\n        if ssl_shutdown_timeout is not sentinel:\n            warnings.warn(\n                \"The ssl_shutdown_timeout parameter is deprecated and will be removed in aiohttp 4.0\",\n                DeprecationWarning,\n                stacklevel=2,\n            )\n\n        if connector is None:\n            connector = TCPConnector(ssl_shutdown_timeout=ssl_shutdown_timeout)\n        # Initialize these three attrs before raising any exception,\n        # they are used in __del__\n        self._connector = connector\n        self._loop = loop","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/aio-libs/aiohttp/blob/c0ef574e29109210e96e652771ae4e7b88615fa4/aiohttp/client.py#L332-L368","documentation":"Raised in ClientSession.__init__ (client.py:350) when the `timeout` argument is not a ClientTimeout instance. aiohttp 3.x replaced scalar timeout values with the ClientTimeout dataclass; passing an int/float (the old requests-style API) or any unrelated type now fails fast instead of being silently misinterpreted. The check runs after `sentinel`/`None` resolution, so only genuinely wrong types reach it.","triggerScenarios":"Calling `ClientSession(timeout=10)`, `ClientSession(timeout=30.0)`, or `session.get(url, timeout=5)`. Anywhere a numeric, tuple, or custom object is passed where aiohttp expects `ClientTimeout(...)`.","commonSituations":"Porting code from `requests` (which accepts numeric timeouts), copy-pasting answers that predate aiohttp 3.0, or using a shared helper that forwards a `timeout` kwarg verbatim from a config file.","solutions":["Wrap the value in ClientTimeout: `from aiohttp import ClientTimeout; ClientSession(timeout=ClientTimeout(total=30))`.","For per-request overrides pass `timeout=ClientTimeout(total=N)` to `session.request(...)` / `session.get(...)`.","If forwarding a possibly-numeric config value, normalize it: `timeout = ClientTimeout(total=t) if isinstance(t, (int, float)) else t`."],"exampleFix":"// before\nsession = aiohttp.ClientSession(timeout=30)\n// after\nfrom aiohttp import ClientTimeout\nsession = aiohttp.ClientSession(timeout=ClientTimeout(total=30))","handlingStrategy":"validation","validationCode":"from aiohttp import ClientTimeout\n\ndef make_timeout(t):\n    if t is None or t is sentinel:\n        return ClientTimeout()\n    if isinstance(t, ClientTimeout):\n        return t\n    if isinstance(t, (int, float)):\n        return ClientTimeout(total=t)\n    raise TypeError(f'unsupported timeout type: {type(t)!r}')","typeGuard":"from aiohttp import ClientTimeout\n\ndef is_valid_timeout(t) -> bool:\n    return t is None or isinstance(t, ClientTimeout)","tryCatchPattern":"try:\n    session = aiohttp.ClientSession(timeout=cfg_timeout)\nexcept ValueError as e:\n    if 'timeout parameter cannot be' in str(e):\n        session = aiohttp.ClientSession(timeout=ClientTimeout(total=30))\n    else:\n        raise","preventionTips":["Always import and use ClientTimeout; never pass raw numbers.","Centralize ClientTimeout construction in a config helper so callers can't pass wrong types.","Run mypy with the aiohttp stubs — the typed `timeout: ClientTimeout` parameter catches numeric misuse at type-check time."],"tags":["client","timeout","configuration","api-misuse"],"analyzedSha":"c0ef574e29109210e96e652771ae4e7b88615fa4","analyzedAt":"2026-08-04T19:51:05.467Z","schemaVersion":2}