I'm looking for a simple way to programmatically invoke a SOAP/RPC call via Python. Something like:
method_to_invoke, args = parse_user_input()
outbound_xml = library.call_remote_method(method_to_invoke, args)
result = requests.post(... data=outbound_xml)
I know there are several Python libraries that support SOAP/RPC calls; however they all do some "magic" and allow for things like:
result = client.service.getPercentBodyFat('jeff', 68, 170)
(previous example taken from suds documentation but the basic principles are the same). This assumes I know the name of the method ahead of time and can't determine it at runtime.
Looking for solutions they are either no longer maintained, or try to do too much "magic". For example see this over-complicated soution or this solution which is basically "Build your own XML and send it over".
Is there any library that can build the "outbound" XML for me without having to go through hoops? I already have a HTTP server which would receive the inbound RPC and want to use requests
to properly handle things like SSL certificate validation.
You can give python-zeep a chance (http://docs.python-zeep.org). It can easily generate the xml which you want to send via the following code:
client = zeep.Client(
wsdl='http://www.webservicex.net/ConvertSpeed.asmx?WSDL')
doc = client.service._binding.create_message('ConvertSpeed', 100,
'kilometersPerhour', 'milesPerhour'))
print(etree.tostring(doc, pretty_print=True))
(I'm the author so let me know if you have any issues with this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With