Skip to content Skip to sidebar Skip to footer

Python Elementtree Find Function Reads Signature As Empty (None)

I'm trying to read Signature, SignatureValue and SignedInfo from signed XML in Python with ElementTree but it reads as None. Other xml attributes are read fine. How can I read Sign

Solution 1:

Its because you have namespace on the Signature element, what you can do is find the element with the namespace

print response_xml.find('{http://www.w3.org/2000/09/xmldsig#}Signature')

then you will have to take the signature element and find all sub elements from it

something like this:

namespace = "{http://www.w3.org/2000/09/xmldsig#}"
signature_elem = response_xml.find(namespace +'Signature')
print signature_elem
print signature_elem.find(namespace+'SignatureValue')
print signature_elem.find(namespace+'SignedInfo')

Post a Comment for "Python Elementtree Find Function Reads Signature As Empty (None)"