我正在集成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上显示的内容。 最佳答案
您链接的文档说:
需要RequesterID来指定谁在发出请求。
您的requestDictionary
有一个用于RequesterID的项目:
...
"RequesterID": '',
...
你的错误是说
缺少元素值(GetPostageLabel.LabelRequest.Value)
我认为您缺少RequesterID的值。