我想通过 WSDL 作为 SOAP 请求发送数据。到目前为止,我可以使用下面的结构来完成此操作,但是现在需要一个标签,并且我想在没有该标签的情况下发送包裹。我已阅读文档,它说对于我想在验证中省略的任何标记,最佳选择是 zeep.xsd.SkipValue,因为 zeep 会验证所有内容。问题是我使用 zeep.xsd.SkipValue 并且生成的 xml 将 SkipValue 填充为标签的值,例如 'projectAa'='SkipValue'
我的代码是
applicationData = {
'techSheet': {
'code': "test",
'projectAa': zeep.xsd.SkipValue,
'email': "test",
'TechList': {
'Tech': {
'publicValue': "0",
'privateValue': "0",
'requestedValue': "0",
'TechBudgetList': {
'TechBudget': expenses
},
}
}
},
'techSheetEvaluation': {
'projectAa':zeep.xsd.SkipValue,
'decisionNumber': '-',
'evaluationStatus': '1',
}
}
print(zeep.xsd.SkipValue)
response = client.service.addTechnicalSheetAndEvaluation(**applicationData)
print("OPSAA CODE IS ", response)
当我执行时
response = client.service.addTechSheetEvaluation(**applicationData)
生成的 xml 是使用等于字符串 SkipValue 的 projectAa 生成的,而不是跳过特定标记的验证。
...
<techSheet email="" contactEmail="" code="0000356060" projectAa="SkipValue">
<TechList>
<Tech requestedValue="0" privateValue="0" publicValue="0">
<TechBudgetList>
<TechBudget xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" aa="1" investmentDescription="Δαπάνες Πρόωρης Συνταξιοδότησης" requestedValue="2470.84" privateValue="0" publicValue="2470.84" actionCode="97.1_21A" expenseSubcategoryCode="M113" xsi:type="ns0:techBudgetAnalysisBase"/>
</TechBudgetList>
</Tech>
</TechList>
</techSheet>
<techSheetEvaluation evaluationStatus="1" decisionNumber="-" projectAa="SkipValue"/>
...
问题是您错误地使用了 zeep.xsd.SkipValue。 zeep.xsd.SkipValue 是一个特殊值,它告诉 Zeep 跳过特定字段的验证。但是,它并不意味着用作字段的实际值。
要解决该问题,您需要创建一个继承自zeep.xsd.SkipValue的新类。这个新类将重写 str() 方法以返回空字符串。这将确保生成的 XML 不包含字符串“SkipValue”。
class SkipValue(zeep.xsd.SkipValue):
def __str__(self):
return ""
applicationData = {
'techSheet': {
'code': "test",
'projectAa': SkipValue(),
'email': "test",
'TechList': {
'Tech': {
'publicValue': "0",
'privateValue': "0",
'requestedValue': "0",
'TechBudgetList': {
'TechBudget': expenses
},
}
}
},
'techSheetEvaluation': {
'projectAa': SkipValue(),
'decisionNumber': '-',
'evaluationStatus': '1',
}
}
response = client.service.addTechnicalSheetAndEvaluation(**applicationData)
这将生成以下 XML:
<techSheet email="" contactEmail="" code="0000356060"/>
<techSheetEvaluation evaluationStatus="1" decisionNumber="-" />
请注意,techSheet 和 techSheetEvaluation 元素中都缺少 projectAa 标签。这是因为 Zeep 跳过了对 projectAa 字段的验证。