mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.87k stars 579 forks source link

202 Response with Content Fails #1333

Open tseader opened 1 year ago

tseader commented 1 year ago

Experiencing Fault with "Unknown fault occured" message when a 202 status-code returns with content.

Context

Test to Prove Issue

Runnable test below when in tests/test_wsdl_soap.py. Derived test from a combination of the following two existing tests:

def test_response_202_with_content():
    """Test 202 response with content that passes with patch"""
    data = """
        <?xml version="1.0"?>
        <soapenv:Envelope
            xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:stoc="http://example.com/stockquote.xsd">
           <soapenv:Header/>
           <soapenv:Body>
              <stoc:TradePrice>
                 <price>120.123</price>
              </stoc:TradePrice>
           </soapenv:Body>
        </soapenv:Envelope>
    """.strip()

    response = stub(status_code=202, content=data, encoding="utf-8", headers={})
    client = Client("tests/wsdl_files/soap.wsdl")
    binding = client.service._binding
    result = binding.process_reply(client, binding.get("GetLastTradePrice"), response)
    assert result == 120.123

Issue Source Identified

The issue has been traced to line 228 of zeep.wsdl.bindings.soap module, in the process_reply function.

Suggested change:

From if response.status_code != 200 or fault_node is not None: To: if response.status_code not in (200, 202) or fault_node is not None:

Alternatively, could let pass more HTTP status codes in the 2xx range if appropriate (shrug)