Note that there are some explanatory texts on larger screens.

plurals
  1. POobjectify and etree elements
    primarykey
    data
    text
    <p>The module I've been writing works finestkind with the test data file, but totally moofs on the live data from flickrapi.</p> <p>After days of frustration (see, I DO have a lot of nothing to do!) I think I found the problem, but I don't know the fix for it. </p> <ul> <li>Internal test data returns a type() of: <code>&lt;type 'str'&gt;</code> </li> <li>External test data returns a type() of: <code>&lt;type 'str'&gt;</code> ## opening &amp; reading external XML</li> <li>Live data returns a type() of: <code>&lt;class<br> 'xml.etree.ElementTree.Element'&gt;</code></li> </ul> <p>Beyond this point in the module, I use objectify. Objectify parses <code>&lt;type 'str'&gt;</code> just fine, but it <strong><em>will not</em></strong> read the etree elements. I <em>think</em> I need to convert the class 'xml.etree.ElementTree.Element' to str(), but haven't sussed that out yet.</p> <p>The error I get from objectify.fromstring() is:</p> <pre><code>Traceback (most recent call last): File "C:\Mirc\Python\Temp Files\test_lxml_2.py", line 101, in &lt;module&gt; 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 </code></pre> <p>Please help before the boss turns loose those damn flying monkeys again!!!</p> <pre><code>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)) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload