python lxml xml.etree.ElementTree.Element 到字符串不会转换

Ant*_*man 3 python xml lxml elementtree

    type(ikePanProfiles)
    <class 'xml.etree.ElementTree.Element'>

    etree.tostring(ikePanProfiles)
    Traceback (most recent call last):
     File "<input>", line 1, in <module>
     File "src/lxml/etree.pyx", line 3367, in lxml.etree.tostring 
    (src/lxml/etree.c:82622)
    TypeError: Type 'Element' cannot be serialized.
Run Code Online (Sandbox Code Playgroud)

我正在访问一个以“xml.etree.ElementTree.Element”对象类型进行响应的 API,所以我不确定如何隐藏此字符串?

Jar*_*uen 5

您的元素是xml库中的一个对象,您正尝试使用lxml它来字符串化。要么更改代码,使元素成为lxml库中的对象,要么使用xml.etree.ElementTree.tostring字符串化它。