4
我了解如何向SOAP请求添加标头。但是,这会产生一个与我需要传递的不匹配的标题。返回此标题:将名称空间添加到Suds中的默认WSSE安全对象
<SOAP-ENV:Header>
<wsse:Security mustUnderstand="true">
<wsse:UsernameToken>
<wsse:Username>CABLE</wsse:Username>
<wsse:Password>CABLE</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
不过,我需要修改头的命名空间通过特定的命名空间的安全对象和UsernameToken的对象。我似乎无法弄清楚如何覆盖提供的默认值。
<soapenv:Header>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
http://schemas.xmlsoap.org/ws/2002/07/secext
<wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility">
<wsse:Username>CABLE</wsse:Username>
<wsse:Password Type="wsse:PasswordText">CABLE</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
这里是Python代码,以生成上述
security = Security()
token = UsernameToken('CABLE', 'CABLE')
security.tokens.append(token)
client.set_options(wsse=security)
谢谢!它还解决了我在密码元素上使用suds wsse支持和缺少类型属性的问题(使用passwd.set('Type',“http://docs.oasis-open.org/wss/2004/01/oasis-200401 -wss-username-token-profile-1.0#PasswordText“)来设置属性。 – sunew