我在 Python 上使用 Google App Engine 并尝试获取 GZipped XML 文件并使用 LXML 的 iterparse 对其进行解析。我使用来自 lxml.de 的示例来创建以下代码:
import gzip, base64, StringIO
from lxml import etree
from google.appengine.ext import webapp
from google.appengine.api.urlfetch import fetch
class Catalog(webapp.RequestHandler):
user = xxx
password = yyy
catalog = fetch('url',
headers={"Authorization":
"Basic %s" % base64.b64encode(user + ':' + password)}, deadline=600)
items = etree.iterparse(StringIO.StringIO(catalog), tag='product')
for _, element in items:
print('%s -- %s' % (element.findtext('name'), element[1].text))
element.clear()
当我运行它时,它给了我以下错误:
for _, element in coupons:
File "iterparse.pxi", line 491, in lxml.etree.iterparse.__next__ (src/lxml\lxml.etree.c:98565)
File "iterparse.pxi", line 543, in lxml.etree.iterparse._read_more_events (src/lxml\lxml.etree.c:99086)
File "parser.pxi", line 590, in lxml.etree._raiseParseError (src/lxml\lxml.etree.c:74791)
XMLSyntaxError: Specification mandate value for attribute object, line 1, column 53
这个错误是什么意思?我猜测 XML 文件格式不正确,但是我不知道在哪里寻找问题。任何帮助,将不胜感激!