1
我有一个旨在访问联机API(Google Search Appliance)的脚本,它需要发布特定的xml格式。我已经使用lxml构建了一个xml文档,但是我的问题是,在尝试创建根节点时,我得到一个异常(ValueError: Invalid namespace URI
Exception)。下面是完整的例子:命名空间URI无效使用Python的lxml
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)
而抛出的异常如下:
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}'
谁能解释这是什么意思?我在http代理的后面,但我不认为这是一个问题,因为当我删除GSA名称空间并仅保留w3.org名称空间时,我没有得到该异常。