Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of faults with empty namespace #4

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/zeep/wsdl/bindings/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,23 @@ def process_error(self, doc, operation):
detail=etree_to_string(doc),
)

def get_text(name):
def get_node(name):
child = fault_node.find(name, namespaces=fault_node.nsmap)
if child is not None:
return child
child = fault_node.find(name)
return child

def get_text(name):
child = get_node(name)
if child is not None:
return child.text

raise Fault(
message=get_text("faultstring"),
code=get_text("faultcode"),
actor=get_text("faultactor"),
detail=fault_node.find("detail", namespaces=fault_node.nsmap),
detail=get_node("detail"),
)

def _set_http_headers(self, serialized, operation):
Expand Down
33 changes: 33 additions & 0 deletions tests/test_wsdl_soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,39 @@ def test_soap11_process_error():
"utf-8"
)

responseWithEmptyNamespaceInFault = load_xml(
"""
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://example.com/my/schema">
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns="">fault-code-withEmptyNamespace</faultcode>
<faultstring xmlns="">fault-string-withEmptyNamespace</faultstring>
<detail xmlns="">
<myFaultDetails xmlns="http://example.com/my/schema">
<message>detail-message-withNamespace</message>
<errorcode>detail-code-withNamespace</errorcode>
</myFaultDetails>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
"""
)

try:
binding.process_error(responseWithEmptyNamespaceInFault, None)
except Fault as exc:
assert exc.message == "fault-string-withEmptyNamespace"
assert exc.code == "fault-code-withEmptyNamespace"
assert exc.actor is None
assert exc.subcodes is None
assert "detail-message-withNamespace" in etree.tostring(exc.detail).decode(
"utf-8"
)



def test_soap12_process_error():
response = """
Expand Down