如何解决“ zeep.exceptions.ValidationError:缺少元素值”

时间:2019-06-19 09:42:35

标签: python soap wsdl zeep

我正在集成Endicia SOAP,但出现此错误:

"Missing element %s" % (self.name), path=render_path)
zeep.exceptions.ValidationError: Missing element
Value (GetPostageLabel.LabelRequest.Value)

这是我的代码:

import xml.etree.ElementTree as ET
from zeep import Client, Settings, xsd
from zeep.exceptions import Fault, TransportError, XMLSyntaxError

# Set Connection
settings = Settings(strict=False, xml_huge_tree=True)
client = Client(
'https://elstestserver.endicia.com/LabelService/EwsLabelService.asmx?wsdl',
settings=settings)

# Set label request dictionary
requestDictionary = {
    "MailClass": 'Priority',
    "WeightOz": 16,
    "RequesterID": '',
    "AccountID": '',
    "PassPhrase": '',
    "PartnerCustomerID": '100',
    "PartnerTransactionID": '200',
    "ToName": 'Margaret D Norris',
    "ToAddress1": '2461  Romano Street',
    "ToCity": 'Cambridge',
    "ToState": 'MA',
    "ToPostalCode": '02141',
    "FromCompany": 'Camilla R Goforth',
    "FromName": 'Camilla R Goforth',
    "ReturnAddress1": '1670  Oliverio Drive',
    "FromCity": 'Satanta',
    "FromState": 'KS',
    "FromPostalCode": '67870',
    "CostCenter":'0'
}



# Try operation
try:
    response = client.service.GetPostageLabel(LabelRequest=requestDictionary)
    print(response)


except Fault as error:
    print(ET.tostring(error.detail))


有人可以帮忙吗?

我尝试更改输入数据结构,但无济于事 我希望response = client.service.GetPostageLabel(LabelRequest=requestDictionary)print(response)的输出类似于在this page上显示的内容。

1 个答案:

答案 0 :(得分:0)

您链接的文档说:

  

需要RequesterID来指定谁在发出请求。

您的requestDictionary有一个用于RequesterID的项目:

...
"RequesterID": '',
...

您的错误是在说

  

缺少元素值(GetPostageLabel.LabelRequest.Value)

我认为您缺少RequesterID的值。