我需要将从响应中接收到的xml打印到控制台:
import xml.etree.ElementTree as ET
xml = req.text
result = ET.ElementTree(ET.fromstring(xml))
rough_string = ET.tostring(result, "utf-8")
reparsed = minidom.parseString(rough_string)
print reparsed.toprettyxml(indent="\t")
错误信息:
AttributeError: 'ElementTree' object has no attribute 'tag'
File "....", line x, in ...
rough_string = ET.tostring(result, "utf-8")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 1126, in tostring
ElementTree(element).write(file, encoding, method=method)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 820, in write
serialize(write, self._root, encoding, qnames, namespaces)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/etree/ElementTree.py", line 900, in _serialize_xml
tag = elem.tag
AttributeError: 'ElementTree' object has no attribute 'tag'