当使用Zeep(Python3.7)将数据发送到soapi时,生成的wsse:Security
头是http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd
其结果是错误:
zeep.exceptions.Fault: SOAP Security Header UsernameToken is required for operation 'ProcessMessage'
如果我随后获取原始请求XML并将其发送到API(通过SOAPUI),我会得到相同的问题。但是,如果我将此值更改为示例中与http://schemas.xmlsoap.org/ws/2002/07/secext
的WSDL一起发送的值,则请求成功完成,并从API获得成功响应。在
我尝试了很多方法,包括在Security element header中明确定义命名空间:
^{pr2}$然而,这似乎并不能解决这个问题。在
我也试过:
client.set_default_soapheaders([header_value])
再说一次,没有快乐。在
在Zeep中有没有一种方法可以做到这一点(我对另一个SOAP包持开放态度,尽管Zeep似乎是维护最活跃的一个)?或者我的请求格式中完全缺少可能导致此问题的某些内容?在
代码如下。提前谢谢你!在
header = xsd.Element(
'Security',
xsd.ComplexType([
xsd.Element(
'UsernameToken',
xsd.ComplexType([
xsd.Element('Username', xsd.String()),
xsd.Element('Password', xsd.String()),
])
)
])
)
header_value = header(UsernameToken={'Username': user, 'Password': password})
client.service.ProcessMessage(_soapheaders=[header_value], Payload=dataobj)
对于生成的XML,上面的示例给出了以下内容:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
<soap-env:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>username</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
### REQUEST BODY
</soap-env:Body>
</soap-env:Envelope>
这不起作用
但是,只需将原始XML中的wsse:Security xmlns:wsse
值更改为http://schemas.xmlsoap.org/ws/2002/07/secext
,并将其粘贴到SOAPUI中,就可以了。在
通过切换到使用不同的SOAP库来解决。在
相关问题 更多 >
编程相关推荐