D4Vinci/Scrapling · error · SessionConfigurationError

{self.__class__.__name__}.configure_sessions() did not add a

Error message

{self.__class__.__name__}.configure_sessions() did not add any sessions

What it means

Spider.__init__ verifies that configure_sessions() registered at least one session. If your override returns without adding any session via manager.add(), the spider cannot fetch anything and init fails fast.

Source

Thrown at scrapling/spiders/spider.py:151

            Path(self.log_file).parent.mkdir(parents=True, exist_ok=True)
            file_handler = logging.FileHandler(self.log_file)
            file_handler.setFormatter(formatter)
            self.logger.addHandler(file_handler)

        self.crawldir: Optional[Path] = Path(crawldir) if crawldir else None
        self._interval = interval
        self._engine: Optional[CrawlerEngine] = None
        self._original_sigint_handler: Any = None

        self._session_manager = SessionManager()

        try:
            self.configure_sessions(self._session_manager)
        except Exception as e:
            raise SessionConfigurationError(f"Error in {self.__class__.__name__}.configure_sessions(): {e}") from e

        if len(self._session_manager) == 0:
            raise SessionConfigurationError(f"{self.__class__.__name__}.configure_sessions() did not add any sessions")

        self.logger.info("Spider initialized")

    async def start_requests(self) -> AsyncGenerator[Request, None]:
        """Generate initial requests to start the crawl.

        By default, this generates Request objects for each URL in `start_urls`
        using the session manager's default session and `parse()` as callback.

        Override this method for more control over initial requests
        (e.g., to add custom headers, use different callbacks, etc.)
        """
        if not self.start_urls:
            raise RuntimeError(
                "Spider has no starting point, either set `start_urls` or override `start_requests` function."
            )

        for url in self.start_urls:

View on GitHub (pinned to 5d213a2d47)

Solutions

  1. Call manager.add(id, session) at least once inside the override, e.g. manager.add("default", FetcherSession())
  2. If you don't need custom sessions, delete the override entirely — the base implementation registers a default FetcherSession

Example fix

// before
def configure_sessions(self, manager):
    pass  # nothing added

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

Strategy: validation

Validate before calling

def configure_sessions(self, manager):
    manager.add("default", FetcherSession())
    assert len(manager) > 0, "at least one session required"

Prevention

When it happens

Trigger: Overriding configure_sessions(self, manager) but forgetting to call manager.add(...); conditional logic in the override that skipped all add() calls (e.g. an if branch that never ran); overriding only to inspect the manager without adding sessions.

Common situations: Copying a skeleton override from docs and not filling it in; scaffolding a new spider class with empty hook methods; early-return statements placed before add() calls.

Related errors


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