[英]How to post xml data to soap service and process properly via spyne Python?
I want to get xml body:我想得到 xml 身体:
<root>
<row>
<param1>value1</param1>
<param2>value2</param2>
</row>
<row>
<param1>value3</param1>
<param2>value4</param2>
</row>
</root>
in param input_data in xml form.在 xml 形式的参数 input_data 中。 My code is:我的代码是:
from spyne import Application, rpc, ServiceBase, Unicode
from lxml import etree
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
class TestService(ServiceBase):
@rpc(Unicode, _returns=Unicode)
def load_data(ctx, input_data):
print(etree.tostring(ctx.in_document))
print('\n')
print(input_data)
app = Application([TestService], tns='PostData',
in_protocol=Soap11(),
out_protocol=Soap11(),
)
application = WsgiApplication(app)
if __name__ == '__main__':
from wsgiref.simple_server import make_server
server = make_server('0.0.0.0', 8090, application)
server.serve_forever()
raw XML in Postman: Postman 中的原始 XML:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tran="PostData">
<soapenv:Header/>
<soapenv:Body>
<tran:load_data>
<tran:input_data>
<root>
<row>
<param1>value1</param1>
<param2>value2</param2>
</row>
<row>
<param1>value3</param1>
<param2>value4</param2>
</row>
</root>
</tran:input_data>
</tran:load_data>
</soapenv:Body>
</soapenv:Envelope>
With current implementation it doesn't work, param input_data is not shown (print(input_data)).对于当前的实现,它不起作用,参数 input_data 没有显示(打印(输入数据))。 Maybe need change param in @rpc?也许需要更改@rpc 中的参数? There can be many raw bodies.可以有许多原始的身体。 (Next step is to translate xml to json and load into table and I need data in xml format) How can I do it? (下一步是将 xml 转换为 json 并加载到表中,我需要 xml 格式的数据)我该怎么做? Thanks谢谢
First, read the manual.首先,阅读手册。 Here's the relevant chapter: http://spyne.io/docs/2.10/manual/03_types.html这是相关章节: http://spyne.io/docs/2.10/manual/03_types.html
There are also a bunch of examples in the spyne repository: https://github.com/arskom/spyne/tree/master/examples spyne存储库中还有一堆示例: https://github.com/arskom/spyne/tree/master/examples
class Row(ComplexModel):
param1 = Unicode
param2 = Unicode
class Root(ComplexModel):
row = Row
class TestService(ServiceBase):
@rpc(Root, _returns=Unicode)
def load_data(ctx, input_data):
print(etree.tostring(ctx.in_document))
print('\n')
print(input_data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.