[Python] Spyne define a function that accepts array of complex types

Discussão em 'Python' iniciado por Stack, Novembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to make a SOAP function on my spyne server that follows this structure.

    <soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Body>
    <test_function xmlns:ns0="Test">
    <resource>
    <item>
    <material>gold</material>
    </item>
    <item>
    <material>silver</material>
    </item>
    </resource>
    </test_function>
    </soap-env:Body>
    </soap-env:Envelope>


    Code that is closest to work is this

    class Material(ComplexModel):
    material = Unicode

    class Resource(Array): # Changing to ComplexModel doesn't affect
    item = Material

    class Soap(ServiceBase):
    @rpc(Resource)
    def test_function(ctx, resource):
    print(resource)
    return "Yes"


    app = Application(
    [Soap],
    tns='Test',
    in_protocol=Soap11(),
    out_protocol=Soap11()
    )
    application = WsgiApplication(app)


    I make requests with zeep and code of client looks like this

    params = {
    "resource": [
    {"item": {"material": "gold"}},
    {"item": {"material": "silver"}}
    ]
    }

    ...

    with zeep_client as client:
    msg = client.create_message(
    client.service, 'test_function', **params)



    But my request have only one <item>, second one is missing. I tried to play Array in different places but they either makes code not working (unexpected arguments errors) or doesn't change anything.

    Decorating function with @rpc(Array(Resource)) leads to

    `TypeError: {Test}ResourceArray() got an unexpected keyword argument 'item'. Signature: `Resource: {Test}Resource[]`

    Continue reading...

Compartilhe esta Página