pythonsoapspyne

Print out entire SOAP request in python spyne server


I have a SOAP server which is written using spyne. Here is the code:

class myService(ServiceBase):

    @rpc(Integer, String, _returns=String)
    def my_method(ctx):
        sys.stdout.write("Request for `myService`: {}\n".format(ctx))
        return "0," + "".join(random.sample(string.hexdigits, 16))


application = Application(
    [myService],
    tns=NAMESPACE,
    in_protocol=Soap11(validator="lxml"),
    out_protocol=Soap11()
)


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger("spyne.util").setLevel(logging.DEBUG)
    wsgi_app = WsgiApplication(application)
    server = make_server("0.0.0.0", 5555, wsgi_app)
    server.serve_forever()

It is a simulator which is going to mock a real service. I connect them with desired clients, but I'm getting code 400, message Bad HTTP/0.9 request type error for every request. Since I don't have access to the clients who are calling my mock server, I want to print out the received request in my server. Above code does not work (sys.stdout.write).

EDIT 1:

I changed sys.stdout to python logger:

import logging
logger = logging.getLogger("spyne.util")
...
...
...
logger.info("Request for `myService`: {}\n".format(ctx))

But nothing is printed and I'm getting following error this time:

code 400, message Bad request syntax

Solution

  • The following should do it:

    logging.getLogger('').setLevel(logging.DEBUG)
    logging.getLogger('spyne.protocol').setLevel(logging.DEBUG)
    logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)