0

regarding Authentification on DHL-SOAP API with zeep

i tried authenticating with the code provided by derAndre. but for me it didn't worked.

i am just trying to get the "getVersion" operation but it failed because of the Authentification.
But if i use it, i get an 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'

this is the code, and i'm not getting the hang of it.

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])
Bjoern
  • 3
  • 3
  • How does the service documentation say you should authenticate? Is it with SOAP headers? Is it Basic Authentication in HTTP headers? Before jumping to code, have you tried to get a successful call by using something like [SoapUI](https://www.soapui.org/downloads/soapui/), just to see what kind of request you need to replicate in your code? – Bogdan Feb 23 '21 at 13:53
  • Okay, the Authentification seems to work the problem was, that the header value user / signature must be a different user, provided by the testing environment. Now i have another Problem, but i will first post the question in the DHL community – Bjoern Feb 24 '21 at 14:32

1 Answers1

1

I was facing similar problem and found a solution by following zeep debugger

Note that, my purpose was to test data via sandbox endpoint: https://cig.dhl.de/services/sandbox/soap

However, the debugger said, it was sending request to production endpoint: https://cig.dhl.de/services/production/soap

The problem was in the wsdl file that I stored geschaeftskundenversand-api-3.2.2.wsdl locally.

If you notice, by the end of the file production address has been set to production by default.

 <soap:address location="https://cig.dhl.de/services/production/soap"/>

Just set it to -

<soap:address location="https://cig.dhl.de/services/sandbox/soap"/>

Everything else are okay.

One just needs to make sure that the endpoint is okay. Because credentials are bit different for these two endpoints.

Mahbubur Rahman
  • 361
  • 2
  • 8
  • 6 hours of my life, lost – dasfacc Sep 22 '22 at 14:05
  • what's the status now? – Mahbubur Rahman Sep 22 '22 at 16:52
  • I mean, I tried using production keys to see if this was the problem before and it didn't work, so even though I changed the .wsdl to use the sandbox endpoint I still changed my code so that zeep creates the .xml payload, which I save to a file and then I send that payload using a requests session. In any case, thank You for Your answer – dasfacc Sep 23 '22 at 11:27