Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python lxml xml.etree.ElementTree.Element to string will not convert

    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.

I'm accessing an API that responds in kind with an object type of "xml.etree.ElementTree.Element" So I'm not sure how to covert this tostring?

like image 648
Anton N Coleman Avatar asked Feb 19 '26 09:02

Anton N Coleman


1 Answers

Your element is an object from the xml library and you are trying to use lxml to stringify it. Either change your code so that your element is an object from the lxml library, or use xml.etree.ElementTree.tostring to stringify it.

like image 199
Jared Goguen Avatar answered Feb 21 '26 23:02

Jared Goguen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!