D4Vinci/Scrapling · error · TypeError

Session type {type(client)} not supported for async fetch

Error message

Session type {type(client)} not supported for async fetch

What it means

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.

Source

Thrown at scrapling/spiders/session.py:126

            if sid in self._lazy_sessions and not session._is_alive:
                async with self._lazy_lock:
                    if not session._is_alive:
                        await session.__aenter__()

            if isinstance(session, FetcherSession):
                client = session._client

                if isinstance(client, _ASyncSessionLogic):
                    kwargs = request._session_kwargs.copy()
                    method = cast(SUPPORTED_HTTP_METHODS, kwargs.pop("method", "GET"))
                    response = await client._make_request(
                        method=method,
                        url=request.url,
                        **kwargs,
                    )
                else:
                    # Sync session or other types - shouldn't happen in async context
                    raise TypeError(f"Session type {type(client)} not supported for async fetch")
            else:
                response = await session.fetch(url=request.url, **request._session_kwargs)

            response.request = request
            # Merge request meta into response meta (response meta takes priority)
            response.meta = {**request.meta, **response.meta}
            return response
        raise RuntimeError("No session found with the request session id")

    async def __aenter__(self) -> "SessionManager":
        await self.start()
        return self

    async def __aexit__(self, *exc) -> None:
        await self.close()

    def __contains__(self, session_id: str) -> bool:
        """Check if a session ID is registered."""

View on GitHub (pinned to 5d213a2d47)

Solutions

  1. Create the FetcherSession in async mode for spiders, e.g. FetcherSession(async_=True) or the async constructor variant documented for the version in use
  2. Use the default configure_sessions() (which registers a compatible session) unless you need custom settings
  3. For browser-based crawls use AsyncDynamicSession or AsyncStealthySession instead — these are always supported by SessionManager.fetch

Example fix

// before
def configure_sessions(self, manager):
    manager.add("default", FetcherSession())  # created in sync mode

// after
def configure_sessions(self, manager):
    manager.add("default", FetcherSession(async_=True))
Defensive patterns

Strategy: validation

Validate before calling

from scrapling.engines.static import _ASyncSessionLogic
from scrapling.fetchers import FetcherSession

sess = FetcherSession(async_=True)
assert isinstance(sess._client, _ASyncSessionLogic), "session is not async-capable"

Type guard

def is_async_fetcher_session(s) -> bool:
    return isinstance(s, FetcherSession) and isinstance(s._client, _ASyncSessionLogic)

Try / catch

except TypeError as e:
    if "not supported for async fetch" in str(e):
        # swap in an async-capable session and retry the request
        ...

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14). Data as JSON: /api/errors/9069e5832567f26e. Report an issue: GitHub.