How to build a SOAP header with zeep

577 views Asked by At

I am trying to understand how to operate a SOAP API using zeep lib for python. Note that I don't even understand much about XML, XSD, etc. So, currently I have a lot of questions about it but for now I will focus on one.

The SOAP endpoint I am trying to access requires a very simple header with a token value that I am able to retrieve through a rest request (which I've already accomplished). The header schema is as follows:

<soap:header>
  <fueloauth>YOUR_ACCESS_TOKEN</fueloauth>
</soap:header>

Using zeep I know that I need to build this header through the xsd method as shown in this link. But I am not really understanding this doc... how can I build this specific header to authenticate the SOAP calls?

Additionally, whats the difference between complex headers and simple headers?

1

There are 1 answers

0
Alexandra Dudkina On

The most simple way to do this would be creating a dict:

header = {
    'fueloauth': '<<YOUR_ACCESS_TOKEN>>'
}

And then calling web service with parameter _soapheaders:

client.service.Method(_soapheaders=header)