python-zeep icon indicating copy to clipboard operation
python-zeep copied to clipboard

zeep.exceptions.ValidationError: Missing element for Any

Open tlc28 opened this issue 2 years ago • 4 comments

Hi,

Disclaimer: I'm new to Zeep and to SOAP in general.

This being said, I'm trying to consume Sympa's SOAP API using Zeep 4.1.0. It's a private Sympa instance so you cannot really test it, but anyway, this is the script I use:

wsdl = "https://sympa.ehess.fr/sympa/wsdl"
client = zeep.Client(wsdl=wsdl)

r = client.service.authenticateRemoteAppAndRun(
    "app_name",
    "app_password",
    "variables",
    "which",
    [],
)
print(r)

This returns an array of list, which is exactly what I'm expecting.

The error occurs when I try to use a different operation, namely review:

wsdl = "https://sympa.DOMAIN.TLD/sympa/wsdl"
client = zeep.Client(wsdl=wsdl)

r = client.service.authenticateRemoteAppAndRun(
    "app_name",
    "app_password",
    "variables",
    "review",
    ["list_name"],
)
print(r)

The error is (I've added 3 print statements that display the "from…"):

from indicators <Element {urn:sympasoap}authenticateRemoteAppAndRun at 0x7ff09cc5ddc0> {
    'appname': 'app_name',
    'apppassword': 'app_password',
    'vars': 'variables',
    'service': 'review',
    'parameters': [
        'list_name'
    ]
} ['authenticateRemoteAppAndRun']
from indicators <Element parameters at 0x7ff09cc5dc40> ['ue341-epistemologies-duales-deca-dela'] ['authenticateRemoteAppAndRun', 'parameters']
from Any <Element parameters at 0x7ff09cc5dc40> NotSet ['authenticateRemoteAppAndRun', 'parameters']
Traceback (most recent call last):
  File "/var/listsem/venv/bin/listsem", line 8, in <module>
    sys.exit(cli())
  File "/var/listsem/venv/lib/python3.9/site-packages/listsem/entry_points/cli.py", line 27, in cli
    return build(read_config_from_env())
  File "/var/listsem/venv/lib/python3.9/site-packages/listsem/infrastructure/typer/__init__.py", line 525, in build
    return cli(obj=config)
  File "/var/listsem/venv/lib/python3.9/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/var/listsem/venv/lib/python3.9/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/var/listsem/venv/lib/python3.9/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/var/listsem/venv/lib/python3.9/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/var/listsem/venv/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/var/listsem/venv/lib/python3.9/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/var/listsem/venv/lib/python3.9/site-packages/typer/main.py", line 497, in wrapper
    return callback(**use_params)  # type: ignore
  File "/var/listsem/venv/lib/python3.9/site-packages/listsem/infrastructure/typer/__init__.py", line 517, in listes_diffusion
    listes_diffusion.creer_liste("nom", "titre")
  File "/var/listsem/venv/lib/python3.9/site-packages/listsem/infrastructure/zeep/__init__.py", line 80, in creer_liste
    resultat = self.__client.service.authenticateRemoteAppAndRun(
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/proxy.py", line 46, in __call__
    return self._proxy._binding.send(
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/wsdl/bindings/soap.py", line 123, in send
    envelope, http_headers = self._create(
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/wsdl/bindings/soap.py", line 73, in _create
    serialized = operation_obj.create(*args, **kwargs)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/wsdl/definitions.py", line 222, in create
    return self.input.serialize(*args, **kwargs)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/wsdl/messages/soap.py", line 79, in serialize
    self.body.render(body, body_value)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 232, in render
    self._render_value_item(parent, value, render_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
    return self.type.render(node, value, None, render_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/types/complex.py", line 295, in render
    element.render(node, element_value, child_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/elements/indicators.py", line 252, in render
    element.render(parent, element_value, child_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 232, in render
    self._render_value_item(parent, value, render_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/elements/element.py", line 256, in _render_value_item
    return self.type.render(node, value, None, render_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/types/complex.py", line 295, in render
    element.render(node, element_value, child_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/elements/indicators.py", line 252, in render
    element.render(parent, element_value, child_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/elements/any.py", line 127, in render
    self.validate(value, render_path)
  File "/var/listsem/venv/lib/python3.9/site-packages/zeep/xsd/elements/any.py", line 189, in validate
    raise exceptions.ValidationError("Missing element for Any")
zeep.exceptions.ValidationError: Missing element for Any

When I run python -m zeep https://sympa.DOMAIN.TLD/sympa/wsdl, I get:

[…]
Service: SympaSOAP
     Port: SympaPort (Soap11Binding: {https://sympa.ehess.fr/sympa/wsdl}SOAP)
         Operations:
[…]
            authenticateRemoteAppAndRun(appname: xsd:string, apppassword: xsd:string, vars: xsd:string, service: xsd:string, parameters: ns0:ArrayOfString) -> return: ns0:ArrayOfString
[…]
            review(list: xsd:string) -> return: ns0:ArrayOfString
[…]
            which() -> return: xsd:string

Any help welcome! Thanks for your time!

-- Tanguy

tlc28 avatar Sep 30 '21 14:09 tlc28

I'm also getting zeep.exceptions.ValidationError: Missing element for Any. when the client is passing array of strings to the function to send to SOAP server.

The same wsdl and function works fine using python2 and SOAPpy; also works fine using perl and SOAP::Lite

Any tips on how to troubleshoot or debug this?

chadn avatar Oct 05 '21 15:10 chadn

Hello guys, have you found any solutions at this point in python3 ?

madushanTHAMB avatar Dec 09 '21 10:12 madushanTHAMB

Hi @madushanTHAMB

No! I'm a bit ashamed to write it, but… I stopped using Zeep (for the time being) and wrote a wrapper that uses Sympa's SOAP API client written in… Perl!

tlc28 avatar Dec 10 '21 08:12 tlc28

I had the same problem and I found the solution be analysing Zeep library code and docs: https://docs.python-zeep.org/en/master/datastructures.html

If you want to send parameter with multiple values, instead of structure like this:

items=[
   {'id': 1, 'name': 'abc1'},
   {'id': 2, 'name': 'abc2'},
]

Try:

items=[`
    {'_value_1': 
        [
            {'id': 1, 'name': 'ok abc1', 'description':'xyz1'},
            {'id': 2, 'name': 'ok abc2', 'description':'xyz2'},
        ]
    },    
]

then you can use parameter: request_data request_data['items']=items (...) and send with Zeep API.

myjazzart avatar Aug 21 '23 19:08 myjazzart