mvantellingen / python-zeep

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

No access to soap-env:Header when Fault rased #647

Open mnacharov opened 6 years ago

mnacharov commented 6 years ago

Hi folks! And Merry Christmas!

We are using zeep library to communicate with Amadeus WS (Example WSDL) for a half of the year.

Those services has an authentication system, which requires passing SessionId in the soap-env:Header. This identifier creates by special service, and each reply of other services contain Session structure as well.

So, I'ts my responsibility to send correct session id, and validate repled value.

Example Fault response:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:awss="http://xml.amadeus.com/ws/2009/01/WBS_Session-2.0.xsd">
  <soap-env:Header>
    <awss:Session>
      <awss:SessionId>079CEGVACT</awss:SessionId>
      <awss:SequenceNumber>2</awss:SequenceNumber>
      <awss:SecurityToken>13Q1G2RB9203T22UGB8L0P6L4H</awss:SecurityToken>
    </awss:Session>
  </soap-env:Header>
  <soap-env:Body>
    <soap:Fault xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <faultcode>soap:Server</faultcode>
      <faultstring>1931|Application|NO MATCH FOR RECORD LOCATOR</faultstring>
      <faultactor>SI:Backend</faultactor>
    </soap:Fault>
  </soap-env:Body>
</soap-env:Envelope>

zeep library totaly fit my needs except the fact that when Fault is raised I don't have access to soap-env:Header. So, I can't check/log that header has correct SessionId. Is it possible to have access to this data?

This script shows __dict__ of zeep.exception.Fault

import pretend
from zeep import exceptions, Client

client = Client('wsdl/1ASIWRIOU6_PDT_auth.wsdl')
with open('response.xml') as f:
    response = pretend.stub(
        status_code=200,
        headers={},
        content=f.read())

operation = client.service._binding._operations['Security_SignOut']
try:
    result = client.service._binding.process_reply(client, operation, response)
except exceptions.Fault as e:
    print(e.__dict__)

# result
# {'message': '1931|Application|NO MATCH FOR RECORD LOCATOR', 'code': 'soap:Server', 'actor': 'SI:Backend', 'detail': None, 'subcodes': None}
# runtime.txt
python==3.6.3 
# requirements.txt
zeep==2.4.0
pkervin commented 5 years ago

Hello, I have same problem with decode information in similar xmlpath like in problem mnach

srikanthreddy2089 commented 5 years ago

This is good way to handle fault exceptions.

What about when we enable to receive xml response instead of dict, how do we handle fault exceptions.

client.settings(strict=False, raw_response=True) # True to skip the parsing step, so that we can get xml response