我刚开始使用其中一个 DHL-SOAP API 并使用 zeep 对 API 运行请求。API 期望和元素验证是这样的:
...
<soapenv:Header>
<cis:Authentification>
<cis:user>USER</cis:user>
<cis:signature>PASSWORD</cis:signature>
</cis:Authentification>
</soapenv:Header>
...
我尝试将身份验证作为 _soapheaders 的一部分传递,如 zeep 文档中所述,dict 表示法和 xsd.Element 表示法似乎都不起作用。
from zeep import Client
from zeep import xsd
client = Client('<URL_TO_WSDL>')
auth_header = {'user': 'user', 'signature': 'signature'}
# dict approach
client.service.DHL_SERVICE(_soapheaders={'Authentification': auth_header})
# xsd approach
header = xsd.Element('Authentification',
xsd.ComplexType([
xsd.Element('user', xsd.String()),
xsd.Element('signature', xsd.String())
])
)
header_values = header(user='user', signature='signature')
client.service.DHL_SERVICE(_soapheaders=[header_values])
我在 DHL 文档中没有在 zeep 文档中找到有用的信息。
先感谢您!
问候