This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: xml.etree.ElementTree Elment.find bug, fails to find tag
Type: enhancement Stage: resolved
Components: XML Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: spacether
Priority: normal Keywords:

Created on 2018-12-19 01:49 by spacether, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg332106 - (view) Author: Justin (spacether) Date: 2018-12-19 01:49
When the following text it loaded in to an ElementTree Element, the find method is unable to find one of the elements without a namespace assigned to it.
import xml.etree.ElementTree as ElementTree

xml_text = """
<ns0:Envelope xmlns:ns0=""><ns0:Body><ns0:Fault><faultcode>a:ActionNotSupported</faultcode><faultstring xml:lang="en-US">The message with Action \'\' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</faultstring></ns0:Fault></ns0:Body></ns0:Envelope>

xml = ElementTree.fromstring(xml_text)
ele = xml.find('faultstring')
ele == None #True
msg332107 - (view) Author: Justin (spacether) Date: 2018-12-19 02:21
Issue was user error. I though that find did a full search of the tree when it only searches children.
Solution is:

ele = xml.find('.//faultstring')
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79712
2018-12-19 02:21:36spacethersetstatus: open -> closed
resolution: not a bug
messages: + msg332107

stage: resolved
2018-12-19 01:49:24spacethercreate