Python 如何在客户端的对象中获取数组?

Python 如何在客户端的对象中获取数组?,python,arrays,soap,spyne,Python,Arrays,Soap,Spyne,我希望在客户端的对象中获得一个数组,但我需要访问字典,如下所示: response.BODY["string"] 首选的解决方案是: response.BODY 代码如下: class ServerResponse(ComplexModel): BODY = Array(String) def __init__(self, BODY): self.BODY = BODY class SomeService(ServiceBase): @rpc(

我希望在客户端的对象中获得一个数组,但我需要访问字典,如下所示:

 response.BODY["string"]
首选的解决方案是:

 response.BODY
代码如下:

class ServerResponse(ComplexModel):
    BODY = Array(String)

    def __init__(self, BODY):
        self.BODY = BODY

class SomeService(ServiceBase):
    @rpc(_returns=ServerResponse)
    def reportEvent(ctx):
        return ServerResponse(["1", "2"])

我是spyne的新手,因此非常欢迎任何帮助。

Array
创建所谓的包装数组。如果您需要一个未包装的,您可以尝试:

class ServerResponse(ComplexModel):
    BODY = String(max_occurs='unbounded')

    def __init__(self, BODY):
        self.BODY = BODY
这将重复
标记,而不是在
标记内重复
标记


然而,这并不是SOAP世界中处理数组的标准方法。一些客户端自动检测包装的数组。如果您的客户端没有,我建议您要么更改客户端库,要么学习如何使用它。

谢谢您,这在客户端也非常有效。