{"record":{"id":"9069e5832567f26e","repo":"D4Vinci/Scrapling","slug":"session-type-type-client-not-supported-for-asyn","errorCode":null,"errorMessage":"Session type {type(client)} not supported for async fetch","messagePattern":"Session type (.+?) not supported for async fetch","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"scrapling/spiders/session.py","lineNumber":126,"sourceCode":"            if sid in self._lazy_sessions and not session._is_alive:\n                async with self._lazy_lock:\n                    if not session._is_alive:\n                        await session.__aenter__()\n\n            if isinstance(session, FetcherSession):\n                client = session._client\n\n                if isinstance(client, _ASyncSessionLogic):\n                    kwargs = request._session_kwargs.copy()\n                    method = cast(SUPPORTED_HTTP_METHODS, kwargs.pop(\"method\", \"GET\"))\n                    response = await client._make_request(\n                        method=method,\n                        url=request.url,\n                        **kwargs,\n                    )\n                else:\n                    # Sync session or other types - shouldn't happen in async context\n                    raise TypeError(f\"Session type {type(client)} not supported for async fetch\")\n            else:\n                response = await session.fetch(url=request.url, **request._session_kwargs)\n\n            response.request = request\n            # Merge request meta into response meta (response meta takes priority)\n            response.meta = {**request.meta, **response.meta}\n            return response\n        raise RuntimeError(\"No session found with the request session id\")\n\n    async def __aenter__(self) -> \"SessionManager\":\n        await self.start()\n        return self\n\n    async def __aexit__(self, *exc) -> None:\n        await self.close()\n\n    def __contains__(self, session_id: str) -> bool:\n        \"\"\"Check if a session ID is registered.\"\"\"","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/spiders/session.py#L108-L144","documentation":"Raised by SessionManager.fetch when a registered FetcherSession's internal client is not an _ASyncSessionLogic instance. The spider engine runs fully async, so a FetcherSession constructed in sync mode (its _client is the sync logic class) cannot serve requests from the async crawl loop.","triggerScenarios":"Calling spider.start()/spider.stream() when configure_sessions() registered a FetcherSession created in synchronous mode (e.g. FetcherSession() used synchronously before, or constructed with the sync client logic). The engine then calls session_manager.fetch(request), the isinstance check at session.py:116 fails, and the TypeError fires.","commonSituations":"Copy-pasting a sync FetcherSession from non-spider example code into configure_sessions; mixing scrapling's sync fetcher API with the spider framework; reusing one session object for both standalone sync fetches and spider crawls.","solutions":["Create the FetcherSession in async mode for spiders, e.g. FetcherSession(async_=True) or the async constructor variant documented for the version in use","Use the default configure_sessions() (which registers a compatible session) unless you need custom settings","For browser-based crawls use AsyncDynamicSession or AsyncStealthySession instead — these are always supported by SessionManager.fetch"],"exampleFix":"// before\ndef configure_sessions(self, manager):\n    manager.add(\"default\", FetcherSession())  # created in sync mode\n\n// after\ndef configure_sessions(self, manager):\n    manager.add(\"default\", FetcherSession(async_=True))","handlingStrategy":"validation","validationCode":"from scrapling.engines.static import _ASyncSessionLogic\nfrom scrapling.fetchers import FetcherSession\n\nsess = FetcherSession(async_=True)\nassert isinstance(sess._client, _ASyncSessionLogic), \"session is not async-capable\"","typeGuard":"def is_async_fetcher_session(s) -> bool:\n    return isinstance(s, FetcherSession) and isinstance(s._client, _ASyncSessionLogic)","tryCatchPattern":"except TypeError as e:\n    if \"not supported for async fetch\" in str(e):\n        # swap in an async-capable session and retry the request\n        ...","preventionTips":["Create every session inside configure_sessions in async mode","Never share a session instance between sync fetcher code and spider crawls","Keep browser crawls on AsyncDynamicSession/AsyncStealthySession"],"tags":["session","async","configuration","type-mismatch"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}