Can't figure out how to return a Python dict/Json as xml using Spyne

[亡魂溺海] 提交于 2021-02-08 11:59:31

问题


I have fired up a WSGI application using Spyne for some SOAP services that I'm trying to build.

I'm absolutely new to SOAP and Spyne in general and I can't seem to figure out how to return a JSON/Python dict as XML. This is what I've done.

class Fruits(ServiceBase):

@rpc(_returns=Iterable(Unicode))
def fruitify(self):
    fruits  = {"apple" : "1", "orange" : ["2","3","4"]}
    return fruits

I think the problem lies in the decorator I'm specifying using _returns.

I tried reading the docs again and again but couldn't figure it out.

The response I'm getting is something like:

    <soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="lets_fruit">
   <soap11env:Body>
      <tns:fruitifyResponse>
         <tns:fruitifyResult>
            <tns:string>apple</tns:string>
            <tns:string>orange</tns:string>
         </tns:fruitifyResult>
      </tns:fruitifyResponse>
   </soap11env:Body>
</soap11env:Envelope>

As evident, it does not have any of my values associated to keys.

Has anybody done something similar and successfully implemented this before?

Thanks in advance!


回答1:


Figured out guys.

I just had to change my _returns=Iterable(Unicode) to _returns=AnyDict.

Thanks!



来源:https://stackoverflow.com/questions/53929155/cant-figure-out-how-to-return-a-python-dict-json-as-xml-using-spyne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!