mvantellingen/python-zeep

Cloudflare and <soap:Header>

JonhSilver opened this issue · 0 comments

zeep 4.1.0

https://draudejai.sodra.lt/edas-external/services/DataService?wsdl

soapui5.7.0 auto create request is:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:typ="http://types.data.external.ws.edas.sodra.epr.lt">
soap:Header<wsse:Security soap:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-49CCFE59547E2413CF17019748335422">wsse:Username.............</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">..................</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">iftd......uKjQ==</wsse:Nonce>wsu:Created2023-12-07T18:47:13.542Z</wsu:Created></wsse:UsernameToken></wsse:Security></soap:Header>
soap:Body
typ:getPossibleDocuments/
</soap:Body>
</soap:Envelope>

and working fine

python zeep create request is:

<soap-env:Envelope xmlns:soap-env="http://www.w3.org/2003/05/soap-envelope">
soap-env:Body
<ns0:getPossibleDocuments xmlns:ns0="http://types.data.external.ws.edas.sodra.epr.lt"/>
</soap-env:Body>
</soap-env:Envelope>

and get Cloudflare chalange
why this happens and how to fix?

class MyLoggingPlugin(Plugin):
    def egress(self, envelope, http_headers, operation, binding_options):
        if not DEBUG: return
        # Format the request body as pretty printed XML
        xml = etree.tostring(envelope, pretty_print=True, encoding='unicode')
        print(f'\nRequest\n-------\nHeaders:\n{http_headers}\n\nBody:\n{xml}')

    def ingress(self, envelope, http_headers, operation):
        if not DEBUG: return
        # Format the response body as pretty printed XML
        xml = etree.tostring(envelope, pretty_print=True, encoding='unicode')
        print(f'\nResponse\n-------\nHeaders:\n{http_headers}\n\nBody:\n{xml}')


        session = Session()
        session.trust_env = True
        session.verify = True
        DEBUG = True
        from zeep.wsa import WsAddressingPlugin

        client = Client(
            wsdl=wsdl
            , wsse=UsernameToken(Username, Password)
            , transport=Transport(session=session)
            ,plugins=[MyLoggingPlugin(),WsAddressingPlugin()]
        )
        with client.settings(raw_response=True):
            node = client.service.uploadEdasDraft(uploadedFileName, encoded_string)