无法弄清楚如何使用 Spyne return a Python dict/Json as xml

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

我已经使用 Spyne 为我尝试构建的一些 SOAP 服务启动了一个 WSGI 应用程序。

总的来说,我对 SOAP 和 Spyne 完全陌生,我似乎无法弄清楚如何 return a JSON/Python dict as XML。这就是我所做的。

class Fruits(ServiceBase):

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

我认为问题出在我使用 _returns 指定的装饰器上。

我一遍又一遍地阅读文档,但还是想不通。

我得到的回复是这样的:

    <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>

很明显,它没有我的任何 values 关联到 keys

有没有人做过类似的事情并成功实施过?

提前致谢!

想通了伙计们。

我只需要将 _returns=Iterable(Unicode) 更改为 _returns=AnyDict

谢谢!