D4Vinci/Scrapling · error · RuntimeError
No sessions registered
Error message
No sessions registered
What it means
The default_session_id property raises RuntimeError when no session has ever been registered. The manager promotes the first added session to default automatically, so hitting this means the SessionManager is empty — typically the spider started making requests before any session was configured.
Source
Thrown at scrapling/spiders/session.py:70
:param session_id: ID of session to remove
"""
if session_id not in self._sessions:
raise KeyError(f"Session '{session_id}' not found")
session = self._sessions.pop(session_id)
if session_id in self._lazy_sessions:
self._lazy_sessions.remove(session_id)
if session and self._default_session_id == session_id:
self._default_session_id = next(iter(self._sessions), None)
return session
@property
def default_session_id(self) -> str:
if self._default_session_id is None:
raise RuntimeError("No sessions registered")
return self._default_session_id
@property
def session_ids(self) -> list[str]:
return list(self._sessions.keys())
def get(self, session_id: str) -> Session:
if session_id not in self._sessions:
available = ", ".join(self._sessions.keys())
raise KeyError(f"Session '{session_id}' not found. Available: {available}")
return self._sessions[session_id]
async def start(self) -> None:
"""Start all sessions that aren't already alive."""
if self._started:
return
for sid, session in self._sessions.items():View on GitHub (pinned to 5d213a2d47)
Solutions
- Register at least one session during spider init: manager.add('default', my_session, default=True).
- If sessions can be removed at runtime, re-register a fallback before popping the last one.
- Make session-creation config unconditional or fail loudly at startup if the list is empty.
Example fix
# before
manager = SessionManager()
print(manager.default_session_id) # RuntimeError
# after
manager.add('main', session, default=True)
print(manager.default_session_id) # 'main' Defensive patterns
Strategy: validation
Validate before calling
if not manager.session_ids:
manager.add('default', Session(), default=True)
assert manager.session_ids, 'no sessions configured before crawl start' Try / catch
try:
sid = manager.default_session_id
except RuntimeError:
raise SystemExit('Configure at least one session before starting the spider') Prevention
- Register a default session unconditionally during spider init.
- Fail fast at startup if the session config list is empty instead of failing per-request later.
When it happens
Trigger: Accessing manager.default_session_id, or issuing a request without an explicit session, on a SessionManager where add() was never called (or every session was popped).
Common situations: Forgetting to configure sessions in spider setup; popping the last session during dynamic reconfiguration while requests are still in flight; constructor code that adds sessions conditionally and the condition was false.
Related errors
- Can't use `adaptive` features while it's disabled globally,
- Session '{session_id}' already registered
- Session '{session_id}' not found. Available: {available}
- Session type {type(client)} not supported for async fetch
- No session found with the request session id
AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14).
Data as JSON: /api/errors/b55d6f3ac77e2207.
Report an issue: GitHub.