{"record":{"id":"689f2ac075472979","repo":"D4Vinci/Scrapling","slug":"itertag-prefix-prefix-r-is-not-defined-in-nam","errorCode":null,"errorMessage":"`itertag` prefix {prefix!r} is not defined in `namespaces`","messagePattern":"`itertag` prefix (.+?) is not defined in `namespaces`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapling/spiders/templates/feed.py","lineNumber":81,"sourceCode":"        for node in self._iter_nodes(root):\n            async for result in self.parse_node(response, node):\n                yield result\n\n    async def parse_node(\n        self, response: \"Response\", node: _Element\n    ) -> AsyncGenerator[Union[Dict[str, Any], Request, None], None]:\n        \"\"\"Override to process one feed node; `node` is a namespace-stripped `lxml` element.\"\"\"\n        raise NotImplementedError(f\"{self.__class__.__name__} must implement parse_node() method\")\n        yield  # Make this a generator for type checkers\n\n    def _wanted_tag(self) -> Tuple[Optional[str], str]:\n        \"\"\"Resolve `itertag` into a `(namespace uri or None, localname)` pair.\"\"\"\n        prefix, _, name = self.itertag.rpartition(\":\")\n        if not prefix:\n            return None, name\n        uri = dict(self.namespaces).get(prefix)\n        if not uri:\n            raise ValueError(f\"`itertag` prefix {prefix!r} is not defined in `namespaces`\")\n        return uri, name\n\n    def _iter_nodes(self, root: _Element) -> Iterator[_Element]:\n        uri, name = self._wanted_tag()\n        for el in root.iter():\n            if isinstance(el.tag, str):\n                qname = etree.QName(el.tag)\n                if qname.localname == name and (uri is None or qname.namespace == uri):\n                    yield self._strip_namespaces(el)\n\n    @staticmethod\n    def _strip_namespaces(node: _Element) -> _Element:\n        \"\"\"Return a copy of `node` with namespaces removed from every tag and attribute.\"\"\"\n        node = deepcopy(node)\n        for el in node.iter():\n            if isinstance(el.tag, str):\n                el.tag = etree.QName(el.tag).localname\n            for key in list(el.attrib):","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/D4Vinci/Scrapling/blob/5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f/scrapling/spiders/templates/feed.py#L63-L99","documentation":"The XML feed template resolves itertag prefixes against the class's namespaces mapping. When itertag is like 'atom:entry' and the prefix ('atom') is not a key in namespaces, _wanted_tag() raises ValueError because the namespace URI needed to match elements is unknown.","triggerScenarios":"Setting itertag = \"atom:entry\" without a matching namespaces = {\"atom\": \"http://www.w3.org/2005/Atom\"} on the class; typos in either the prefix or the namespaces key; overriding namespaces with an empty dict while keeping a prefixed itertag.","commonSituations":"Copy-pasting an itertag from feed examples without the namespace table that accompanied it; feeds that changed their namespace prefix over time; case mismatches between prefix and namespaces key.","solutions":["Add the prefix->URI mapping to the class: namespaces = {\"atom\": \"http://www.w3.org/2005/Atom\"} and keep itertag = \"atom:entry\"","Or use a localname-only itertag (\"entry\") if you want to match the tag in any namespace (uri is None matches all namespaces)"],"exampleFix":"// before\nclass Feed(XMLFeedSpider):\n    itertag = \"atom:entry\"\n\n// after\nclass Feed(XMLFeedSpider):\n    itertag = \"atom:entry\"\n    namespaces = {\"atom\": \"http://www.w3.org/2005/Atom\"}","handlingStrategy":"validation","validationCode":"prefix = itertag.rpartition(\":\")[0]\nif prefix and prefix not in dict(namespaces):\n    raise ValueError(f\"{prefix!r} missing from namespaces\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy itertag and namespaces together from examples","Use localname itertags (no prefix) to match any namespace","Add a unit test that calls _wanted_tag() for validation"],"tags":["feed","xml","namespaces","configuration"],"backgroundTag":null,"analyzedSha":"5d213a2d4764002bfc4fed33c32fe09fa8b0bf7f","analyzedAt":"2026-08-14T22:23:09.440Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}