Hi there, Zeep is a great project! Many thanks for building it.
Is it possible to inspect the XML that will be produced by a Zeep object without actually sending it off to an operation endpoint? This would be a useful tool for debugging.
If this is not already possible, this would make for a useful helper function.
It is possible. Instead of doing this:
client.service.MyService(params,_soapheaders=headers)
do this:
from lxml import etree as ET
#
#<your setup code for zeep here>
#
node = client.create_message(client.service, 'MyService', params = params, _soapheaders=headers)
tree = ET.ElementTree(node)
tree.write('test.xml',pretty_print=True)
Please see http://docs.python-zeep.org/en/master/client.html#creating-the-raw-xml-documents
Hello I followed the example from the above link to create a raw xml for my wsdl. I couldn't generate any raw xml. I modified the request slightly to have None as the 3rd argument.
from zeep import Client
client = Client('http://my-endpoint.com/production.svc?wsdl')
node = client.create_message(client.service, 'myOperation', None)
print(node)
The response is as follows:
Can you please tell what's my mistake?
@prasanth-varikallu I'm _very_ new to zeep, so I may not be recommending the best practice, but you can try a couple approaches:
from zeep.wsdl.utils import etree_to_stringetree_to_string(soap_message).decode()from lxml import etreeetree.tostring(soap_message, pretty_print=True, xml_declaration=True, encoding='utf-8').decode()(I learned the second approach by looking at the implementation of helper function etree_to_string.)
Hope this helps.
@prasanth-varikallu If you use the solution outlined by @andreixk the xml-envelope is saved in a text file named "test.xml" in the folder of your python program.
The print() funtion only returns the element location which in itself is good as it means that your code is creating an element.
Hope this helps.
@andreixk I need help how to save output of zip client service into xml right now its in json formate.
below is the command I am using, also attached snapshot of output I am getting
client.service.Ib440ConfigGet()

Most helpful comment
It is possible. Instead of doing this:
do this: