Authentification On Dhl-soap Api With Zeep
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: ...
Solution 1:
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.
from requests import Session
from requests.auth import HTTPBasicAuth
from zeep import Client
from zeep.transports import Transport
session = Session()
# Authenticate with gateway
session.auth = HTTPBasicAuth(user, password)
client = Client(WSDL_PATH, 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=USER, signature=PASSWORD)
client.service.DHL_SERVICE(_soapheaders=[header_value])
Post a Comment for "Authentification On Dhl-soap Api With Zeep"