I\'d like to pass \"Complex\" Header to a SOAP service with zeep library
Here\'s what it should look like
I recently encountered this problem, and here is how I solved it.
Say you have a 'Security' header that looks as follows...
__USERNAME__
__PWD__
__KEY__
In order to send this header in the zeep client's request, you would need to do the following:
header = zeep.xsd.Element(
'Security',
zeep.xsd.ComplexType([
zeep.xsd.Element(
'UsernameToken',
zeep.xsd.ComplexType([
zeep.xsd.Element('Username',zeep.xsd.String()),
zeep.xsd.Element('Password',zeep.xsd.String()),
])
),
zeep.xsd.Element(
'ServiceAccessToken',
zeep.xsd.ComplexType([
zeep.xsd.Element('AccessLicenseNumber',zeep.xsd.String()),
])
),
])
)
header_value = header(UsernameToken={'Username':'test_user','Password':'testing'},UPSServiceAccessToken={'AccessLicenseNumber':'test_pwd'})
client.service.method_name_goes_here(
_soapheaders=[header_value],#other method data goes here
)