我一直在写的模块与测试数据文件一起工作得很好,但完全用flickrapi处理实时数据。我觉得我发现了这个问题,但是我不知道这个问题的解决方法。我不知道这个问题,但是我不知道这个问题。对象化和etree元素
- 内部测试数据返回的类型():
<type 'str'>
- 外部测试数据返回的类型():的
<type 'str'>
##开口& 读取外部XML - 实时数据返回类型() :
<class
'xml.etree.ElementTree.Element'>
除了模块中的这一点之外,我使用了objectify。 Objectify解析<type 'str'>
就好了,但它不会读取etree元素。我认为我需要将类'xml.etree.ElementTree.Element'转换为str(),但还没有意识到。
从objectify.fromstring错误我得到的()是:
Traceback (most recent call last):
File "C:\Mirc\Python\Temp Files\test_lxml_2.py", line 101, in <module>
Grp = objectify.fromstring(flickr.groups_getInfo(group_id=gid))
File "lxml.objectify.pyx", line 1791, in lxml.objectify.fromstring (src\lxml\lxml.objectify.c:20904)
File "lxml.etree.pyx", line 2994, in lxml.etree.fromstring (src\lxml\lxml.etree.c:63296)
File "parser.pxi", line 1614, in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:93607)
ValueError: can only parse strings
请帮老板再次打开宽松那些该死的猴子飞行前!
import fileinput
from lxml import html, etree, objectify
import re
import time
import flickrapi
if '@N' in gid:
try:
if tst:
Grp = objectify.fromstring(test_data)
else:
Grp = objectify.fromstring(flickr.groups_getInfo(group_id=gid))
fErr = ''
mn = Grp.xpath(u'//group')[0].attrib
res = Grp.xpath(u'//restrictions')[0].attrib
root = Grp.group
gNSID = gid
gAlias = ""
err_tst = getattr(root, "not-there", "Error OK")
gName = getattr(root, "name", "")
Images = getattr(root, 'pool_count', (-1))
Mbr = getattr(root, "members", (-1))
我没有看到'传来的错误objectify.fromstring()'在你的错误堆栈中。 'root = objectify.XML(url)'?你的意思是像'root = objectify.XML(urllib2.urlopen(url).read())'吗? –
对不起,我发布了错误的错误。我已经把正确的一个放在了现在,但错误来自 'Grp = objectify.fromstring(flickr.groups_getInfo(group_id = gid))' –
请注意,在发布的代码中'flickr'是一个自由变量。 – Marcin