Question

Now I am writing simple OpenERP module for my customer. I use SUDS to connect with bank, to get Statements.

I wrote xml request, that works without problem. I get response from bank, that also looks ok. Problem is that response from bank use type, that is not defined in WSDL (I wrote to bank support, that they have a bug).

Traceback (most recent call last):
  File "example3.py", line 112, in <module>
    wiadomosc = client.service.GetStatement(__inject={'msg': xml})
  File "/usr/lib/python2.7/dist-packages/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "/usr/lib/python2.7/dist-packages/suds/client.py", line 773, in invoke
    return self.send(msg)
  File "/usr/lib/python2.7/dist-packages/suds/client.py", line 647, in send
    result = self.succeeded(binding, reply.message)
  File "/usr/lib/python2.7/dist-packages/suds/client.py", line 684, in succeeded
    reply, result = binding.get_reply(self.method, reply)
  File "/usr/lib/python2.7/dist-packages/suds/bindings/binding.py", line 156, in get_reply
    result = self.replycomposite(rtypes, nodes)
  File "/usr/lib/python2.7/dist-packages/suds/bindings/binding.py", line 230, in replycomposite
    sobject = unmarshaller.process(node, resolved)
  File "/usr/lib/python2.7/dist-packages/suds/umx/typed.py", line 66, in process
    return Core.process(self, content)
  File "/usr/lib/python2.7/dist-packages/suds/umx/core.py", line 48, in process
    return self.append(content)
  File "/usr/lib/python2.7/dist-packages/suds/umx/core.py", line 63, in append
    self.append_children(content)
  File "/usr/lib/python2.7/dist-packages/suds/umx/core.py", line 140, in append_children
    cval = self.append(cont)
  File "/usr/lib/python2.7/dist-packages/suds/umx/core.py", line 61, in append
    self.start(content)
  File "/usr/lib/python2.7/dist-packages/suds/umx/typed.py", line 80, in start
    raise TypeNotFound(content.node.qname())
suds.TypeNotFound: Type not found: 'ns29:BkToCstmrStmt'

And types, they provide

    ....
    ns37:BaselineStatus3Code
    ns32:BatchBookingIndicator
    ns33:BatchBookingIndicator
    ns36:BatchBookingIndicator
    ns30:BatchInformation1
    ns31:BatchInformation2
    ns29:BatchInformation2
    ns39:BilateralLimitDetails3
    ns27:BkToCstmrCardRptType
    ns27:BkTxCdType
    ns27:BookgDtType
    ns10:BookingDate
    ns4:Bool
    ns16:Bool
    ns2:Bool
    ns15:Bool
    ns17:BouldingNumber
    ....

So there is no BkToCstmrStmt. How can I make suds to just get response from server, and not analyse it? Just build tree?

Thank you

Was it helpful?

Solution

Still I don't know what is wrong with my code. I solved it in that way:

class MessageInterceptor(suds.plugin.MessagePlugin):
    def __init__(self, *args, **kwargs):
        self.message = None

    def received(self, context):
        #recieved xml as a string
        #print "%s bytes received" % len(context.reply)
        self.message = context.reply
        #clean up reply to prevent parsing
        context.reply = ""
        return context

    message_interceptor = MessageInterceptor()

    client = Client('https://some-adress-to?wsdl',plugins=[message_interceptor])

So now I can call client method

    xml = Raw("""
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
       <soapenv:Header>
       ...
       </soapenv:Header>
       <soapenv:Body>
          <urn1:GetStatement>
             ...
          </urn1:GetStatement>
       </soapenv:Body>
    </soapenv:Envelope>
    """)

    response = client.service.GetStatement(__inject={'msg': xml})

Now suds thinks that got nothing from server. But message we recieved is stored in

message_interceptor.message

Now to get normal dict object from message I do it like that:

import xmltodict
message_interceptor.message = message_interceptor.message.replace('ns17:','')
message_interceptor.message = message_interceptor.message.replace('ns40:','')
message_interceptor.message = message_interceptor.message.replace('soap:','')
response = xmltodict.parse(message_interceptor.message)['Envelope']['Body']['GetStatementResponse']['Document']

Now I can use response as normal response from suds.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top