Getting zeep.exceptions.ValidationError: Missing element for method that worked with suds
Getting zeep.exceptions.ValidationError: Missing element for method that worked with suds
我正在将使用 suds 0.6
开发的代码移植到 zeep 2.4.0
。
以前的肥皂水代码:
client = Client(WSDLfile, proxy=proxy, faults=True)
config = client.factory.create('perUserDataExportConfiguration')
config.param1 = 'something'
...
data = client.service.exportPerUserData(username,password,config)
zeep 代码:
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)
然后我得到zeep.exceptions.ValidationError: Missing element param_i_didnt_set
。查看 config.__values__
显示
OrderedDict([('param1', 'something'),
('param_i_didnt_set', None), ...])
suds
config
对象的相似之处在于它包含许多具有空变量的键,但 suds
不会抛出 ValidationErrors
.
从this Github issue看到zeep.xsd.SkipValue
的用法。所以我用 config
中的 None 替换了任何参数:
for key in config:
if config[key] is None:
config[key] = zeep.xsd.SkipValue
然后 client.service.exportPerUserData(username,password,config)
成功了...
我正在将使用 suds 0.6
开发的代码移植到 zeep 2.4.0
。
以前的肥皂水代码:
client = Client(WSDLfile, proxy=proxy, faults=True)
config = client.factory.create('perUserDataExportConfiguration')
config.param1 = 'something'
...
data = client.service.exportPerUserData(username,password,config)
zeep 代码:
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)
然后我得到zeep.exceptions.ValidationError: Missing element param_i_didnt_set
。查看 config.__values__
显示
OrderedDict([('param1', 'something'),
('param_i_didnt_set', None), ...])
suds
config
对象的相似之处在于它包含许多具有空变量的键,但 suds
不会抛出 ValidationErrors
.
从this Github issue看到zeep.xsd.SkipValue
的用法。所以我用 config
中的 None 替换了任何参数:
for key in config:
if config[key] is None:
config[key] = zeep.xsd.SkipValue
然后 client.service.exportPerUserData(username,password,config)
成功了...