Zeep ValueError:赋予_soapheaders的值无效

时间:2018-10-06 06:41:23

标签: python soap soapheader zeep

我正在尝试通过Zeep进行SOAP调用。 WSDL不包含标头定义,但是SOAP服务器需要以下标头:

<soapenv:Header>
  <ns2:UsernameToken xmlns:ns2="http://siebel.com/webservices">ORNODINTFC_WW@ORACLE.COM</ns2:UsernameToken>
</soapenv:Header>

这是我按照zeep文档进行操作的方式:

header = xsd.Element(
     '{http://siebel.com/webservices}UsernameToken',
      xsd.AnySimpleType()    
)

header_val = header('ORNODINTFC_WW@ORACLE.COM')

client.create_message(client.service, 'process', _soapheaders=[header_val],payload=msg, Mode='ODRFCQUERY', UserName='ORNODINTFC_WW@ORACLE.COM', Password='0r10nTkn')

但是,对于create_message我遇到以下错误

Traceback (most recent call last):
  File "<pyshell#119>", line 1, in <module>
    xml_msg = client.create_message(client.service, 'process', _soapheaders=[header_val],payload=msg, Mode='ODRFCQUERY', UserName='ORNODINTFC_WW@ORACLE.COM', Password='0r10nTkn')
  File "C:\Users\shubgang\AppData\Roaming\Python\Python36\site-packages\zeep\client.py", line 131, in create_message
operation_name, args, kwargs, client=self)
  File "C:\Users\shubgang\AppData\Roaming\Python\Python36\site-packages\zeep\wsdl\bindings\soap.py", line 68, in _create
serialized = operation_obj.create(*args, **kwargs)
  File "C:\Users\shubgang\AppData\Roaming\Python\Python36\site-packages\zeep\wsdl\definitions.py", line 200, in create
return self.input.serialize(*args, **kwargs)
  File "C:\Users\shubgang\AppData\Roaming\Python\Python36\site-packages\zeep\wsdl\messages\soap.py", line 59, in serialize
header = self._serialize_header(headers_value, nsmap)
  File "C:\Users\shubgang\AppData\Roaming\Python\Python36\site-packages\zeep\wsdl\messages\soap.py", line 327, in _serialize_header
raise ValueError("Invalid value given to _soapheaders")
ValueError: Invalid value given to _soapheaders

请提出解决方法

0 个答案:

没有答案