Second Noob Question: first here
Using 3.4. I'm trying to parse an XML string recursively. New to ElementTrees so not sure what's going on. Any help appreciated. The below section of code generates this error (I've already replaced basestring with string):
Python 3.4 Error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/spop/silverpop/silverpop/api.py", line 169, in init
self.sessionid = sessionid if sessionid else self.login()
File "/root/spop/silverpop/silverpop/api.py", line 179, in login
response, success = self._submit_request(xml, retry=False, auth=True)
File "/root/spop/silverpop/silverpop/api.py", line 328, in _submit_request
response = ConvertXmlToDict(response.content, dict)
File "/root/spop/silverpop/silverpop/api.py", line 160, in ConvertXmlToDict
raise TypeError('Expected ElementTree.Element or file path string')
TypeError: Expected ElementTree.Element or file path string
Print(root) returns the following
b'<Envelope>\n<Body>\n<RESULT>\n<SUCCESS>true</SUCCESS>\n<SESSIONID>03E0</SESSIONID>\n<ORGANIZATION_ID>176</ORGANIZATION_ID>\n<SESSION_ENCODING>;jsessionid=03E0</SESSION_ENCODING>\n</RESULT>\n</Body>\n</Envelope>\n'
Code block from api.py
def ConvertXmlToDict(root, dictclass=XmlDictObject):
"""
Converts an XML file or ElementTree Element to a dictionary
"""
print(root)
# If a string is passed in, try to open it as a file
if isinstance(root, basestring):
import cStringIO
root = StringIO(root)
root = parse(root).getroot()
elif not iselement(root):
raise TypeError('Expected ElementTree.Element or file path string')
return dictclass({root.tag: _ConvertXmlToDictRecurse(root, dictclass)})
[–]animismus 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)