I just started working with one of the DHL-SOAP APIs and use zeep to run requests against the API. The API expects and Element Authentification like this:
...
<soapenv:Header>
<cis:Authentification>
<cis:user>USER</cis:user>
<cis:signature>PASSWORD</cis:signature>
</cis:Authentification>
</soapenv:Header>
...
I tried to pass the authentification as part of the _soapheaders as described in the zeep documentation, neigher the dict notation nor the xsd.Element notation seem to work.
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])
I don't find helpful information in the DHL docs not in the zeep documentation.
Thank you in advance!
Regards
Just in case someone ever encounters the same problems. It turned out that the client needs to authenticate at a gateway using HTTPBasicAuth. Additionally, the client had to be created using a Transport with a session in it, carrying the gateway authentication headers. What made the xsd API header approach work was the addition
{http://test.python-zeep.org}. This setup made communication with the API working smoothly.