我尝试安装Yahoo BOSS mashup框架,但运行提供的示例时遇到问题。实施例1,2,5和6起作用,但是3& 4给出Expat错误。这是ex3.py的输出:
gpython examples/ex3.py
examples/ex3.py:33: Warning: 'as' will become a reserved keyword in Python 2.6
Traceback (most recent call last):
File "examples/ex3.py", line 27, in <module>
digg = db.select(name="dg", udf=titlef, url="http://digg.com/rss_search?search=google+android&area=dig&type=both§ion=news")
File "/usr/lib/python2.5/site-packages/yos/yql/db.py", line 214, in select
tb = create(name, data=data, url=url, keep_standards_prefix=keep_standards_prefix)
File "/usr/lib/python2.5/site-packages/yos/yql/db.py", line 201, in create
return WebTable(name, d=rest.load(url), keep_standards_prefix=keep_standards_prefix)
File "/usr/lib/python2.5/site-packages/yos/crawl/rest.py", line 38, in load
return xml2dict.fromstring(dl)
File "/usr/lib/python2.5/site-packages/yos/crawl/xml2dict.py", line 41, in fromstring
t = ET.fromstring(s)
File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 963, in XML
parser.feed(text)
File "/usr/lib/python2.5/xml/etree/ElementTree.py", line 1245, in feed
self._parser.Parse(data, 0)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0
在尝试查询Digg.com时,两个示例似乎都失败了。这是在ex3.py的代码中构造的查询:
diggf = lambda r: {"title": r["title"]["value"], "diggs": int(r["diggCount"]["value"])}
digg = db.select(name="dg", udf=diggf, url="http://digg.com/rss_search?search=google+android&area=dig&type=both§ion=news")
答案 0 :(得分:1)
问题是digg搜索字符串。它应该是“s =”。不是“search =”
答案 1 :(得分:0)
我认为在示例中必须是错误:它获得了JSON结果(实际上,如果您在浏览器中复制并粘贴该URL,则会下载以
开头的文件名search.json){"results":[{"profile_image_url":
"http://a3.twimg.com/profile_images/255524395/KEN_OMALLEY_REVISED_normal.jpg",
"created_at":"Mon, 14 Sep 2009 14:52:07 +0000","from_user":"twilightlords",
即。完全正常的JSON;但是,它不是用json或simplejson等模块解析它,而是尝试将其解析为XML - 显然这种尝试失败了。
我相信修复(可能需要引起维护代码的人注意,以便他们可以合并它)要么是要求XML而不是JSON输出,要么用适当的方法解析生成的JSON而不是试图将其视为XML(不确定如何最好地实现任何更改,因为我不熟悉该代码)。