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名稱空間時,我沒有得到該異常。