在 DHL-SOAP API 上使用 zeep 进行身份验证时出现 401 错误

时间:2021-02-23 13:24:38

标签: python api soap zeep dhl

关于Authentification on DHL-SOAP API with zeep

我尝试使用 derAndre 提供的代码进行身份验证。但对我来说它没有用。

我只是想获取“getVersion”操作,但由于身份验证而失败。
但是如果我使用它,我会得到一个 401。

Server returned response (401) with invalid XML: Invalid XML content received (Space required after the Public Identifier, line 1, column 50).
Content: b'\n\n401 Unauthorized\n\n

Unauthorized

\n

This server could not verify that you\nare authorized to access the document\nrequested. Either you supplied the wrong\ncredentials (e.g., bad password), or your\nbrowser doesn\'t understand how to supply\nthe credentials required.

\n\n'

这是代码,我不明白。

session = Session()
session.auth = HTTPBasicAuth(settings.DHL_SOAP_API_USER,settings.DHL_SOAP_API_PW)
client = Client(settings.DHL_WSDL, transport=Transport(session=session))
# Build Authentification header for API-Endpoint using zeep xsd
header = xsd.Element(
    '{http://test.python-zeep.org}Authentification',
    xsd.ComplexType([
        xsd.Element(
            '{http://test.python-zeep.org}user',
            xsd.String()),
        xsd.Element(
            '{http://test.python-zeep.org}signature',
            xsd.String()),
    ])
)
header_value = header(user=settings.DHL_SOAP_API_USER, signature=settings.DHL_SOAP_API_PW)
result = client.service.getVersion('majorRelease:?', 'minorRelease:?', _soapheaders=[header_value])

0 个答案:

没有答案