D4Vinci/Scrapling · error · ValueError
{self.__class__.__name__} must have a name.
Error message
{self.__class__.__name__} must have a name. What it means
Spider.__init__ requires a non-None name class attribute. The name is used for the logger ('scrapling.spiders.<name>') and log formatting, so an anonymous spider cannot be initialized.
Source
Thrown at scrapling/spiders/spider.py:113
# Fingerprint adjustments
fp_include_kwargs: bool = False
fp_keep_fragments: bool = False
fp_include_headers: bool = False
# Logging settings
logging_level: int = logging.DEBUG
logging_format: str = "[%(asctime)s]:({spider_name}) %(levelname)s: %(message)s"
logging_date_format: str = "%Y-%m-%d %H:%M:%S"
log_file: Optional[str] = None
def __init__(self, crawldir: Optional[Union[str, Path, AsyncPath]] = None, interval: float = 300.0):
"""Initialize the spider.
:param crawldir: Directory for checkpoint files. If provided, enables pause/resume.
:param interval: Seconds between periodic checkpoint saves (default 5 minutes).
"""
if self.name is None:
raise ValueError(f"{self.__class__.__name__} must have a name.")
self.logger = logging.getLogger(f"scrapling.spiders.{self.name}")
self.logger.setLevel(self.logging_level)
self.logger.handlers.clear()
self.logger.propagate = False # Don't propagate to parent 'scrapling' logger
formatter = logging.Formatter(
fmt=self.logging_format.format(spider_name=self.name), datefmt=self.logging_date_format
)
# Add a log counter handler to track log counts by level
self._log_counter = LogCounterHandler()
self.logger.addHandler(self._log_counter)
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)
self.logger.addHandler(console_handler)
View on GitHub (pinned to 5d213a2d47)
Solutions
- Add a unique class attribute: name = "my_spider" on the subclass
- Give each spider a distinct name so per-spider loggers don't collide
Example fix
// before
class MySpider(Spider):
start_urls = ["https://example.com"]
// after
class MySpider(Spider):
name = "my_spider"
start_urls = ["https://example.com"] Defensive patterns
Strategy: validation
Validate before calling
class MySpider(Spider):
name = "my_spider" # required class attribute
assert MySpider.name, "spider must define a name" Prevention
- Set name as the first attribute of every spider class
- Add a startup check/test that instantiates each spider class to catch missing names early
When it happens
Trigger: Defining a Spider subclass without setting `name = "..."` as a class attribute (the base class declares name = None); instantiating the abstract Spider base class directly.
Common situations: Following tutorials for non-scrapling frameworks that don't require names; creating quick test spiders and forgetting the attribute; copying a class and deleting fields while refactoring.
Related errors
- Spider has no starting point, either set `start_urls` or ove
- Cannot use 'proxy_rotator' together with 'proxy' or 'proxies
- This response has no request set yet.
- Unknown parser argument: "{key}"; maybe you meant {cls.parse
- You must pass a keyword to configure, current keywords: {cls
AI-assisted analysis of D4Vinci/Scrapling@5d213a2d47 (2026-08-14).
Data as JSON: /api/errors/588fac756fa4fd11.
Report an issue: GitHub.