Getting zeep.exceptions.ValidationError: Missing element for method that worked with suds
Asked Answered
H

1

7

I'm porting over code that was developed with suds 0.6 over to zeep 2.4.0.

Previous suds code:

client = Client(WSDLfile, proxy=proxy, faults=True)
config = client.factory.create('perUserDataExportConfiguration')
config.param1 = 'something'
...
data = client.service.exportPerUserData(username,password,config)

zeep code:

session = requests.Session()
session.verify = False
transport = Transport(session=session)
client = Client(WSDLfile, strict=False, transport=transport)
config = client.type_factory('ns0').perUserDataExportConfiguration()
config.param1 = 'something'
...
data = client.service.exportPerUserData(username,password,config)

Then I get zeep.exceptions.ValidationError: Missing element param_i_didnt_set. Looking into config.__values__ shows

OrderedDict([('param1', 'something'),
             ('param_i_didnt_set', None), ...])

The suds config object is similar in that it contains a number of keys with empty variables, but suds doesn't throw ValidationErrors.

Headband answered 5/9, 2017 at 20:11 Comment(0)
H
6

From this Github issue I saw the use of zeep.xsd.SkipValue. So I did a replace of any parameter with None in config with that:

for key in config:
    if config[key] is None:
        config[key] = zeep.xsd.SkipValue

And then client.service.exportPerUserData(username,password,config) worked...

Headband answered 5/9, 2017 at 20:21 Comment(1)
This zeep.xsd.SkipValue is so useful, especially since Zeep seems to enforce validation even when the property is deemed nillable in the datacontract. Thanks a lot @HeadbandMilton

© 2022 - 2024 — McMap. All rights reserved.