ewok
ewok

Reputation: 21493

Invalid namespace URI Using Python's lxml

I have a scripts designed to access an online API (Google Search Appliance), which requires a specific xml format be posted. I have built an xml document using lxml, but my problem is that upon attempting to create the root node, I am given a ValueError: Invalid namespace URI Exception. Here is the full example:

gsa_ns="http://schemas.google.com/gsa/2007"
default_ns="http://www.w3.org/2005/Atom"

gsa="{%s}"%gsa_ns
default="{%s}"%default_ns

nsmap={None:default, "gsa":gsa}

entry=et.Element(default+"entry",nsmap=nsmap)

And the exception thrown is below:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lxml.etree.pyx", line 2557, in lxml.etree.Element (src/lxml/lxml.etree.c:50983)
  File "apihelpers.pxi", line 156, in lxml.etree._makeElement (src/lxml/lxml.etree.c:12231)
  File "apihelpers.pxi", line 143, in lxml.etree._makeElement (src/lxml/lxml.etree.c:12097)
  File "apihelpers.pxi", line 257, in lxml.etree._initNodeNamespaces (src/lxml/lxml.etree.c:13125)
  File "apihelpers.pxi", line 1567, in lxml.etree._uriValidOrRaise (src/lxml/lxml.etree.c:24339)
ValueError: Invalid namespace URI u'{http://schemas.googls.com/gsa/2007}'

Can someone explain what this means? I am behind an http proxy, but I don't think that is a problem, as when I remove the GSA namespace and keep only w3.org namespace, I do not get the exception.

Upvotes: 1

Views: 2301

Answers (1)

Cito
Cito

Reputation: 5613

URIs of namespaces are never looked up by the parser, it doesn't matter if you're behind a proxy or not. But the parser in lxml 2.3 checks whether they are valid URIs. So it should be

nsmap = {None: default_ns, "gsa": gsa_ns}

Upvotes: 3

Related Questions