将命名空间添加到 Suds 中的默认 WSSE 安全对象
我了解如何向 SOAP 请求添加标头。但这会生成一个与我需要传递的标头不匹配的标头。返回此标头:
<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>
但是,我需要修改该标头的命名空间以传递 Security 对象和 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)
I understand how to add a header to the SOAP request. But that generates a header that doesn't match the one I need to pass. That returns this header:
<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>
However, I need to modify the namespace of that header to pass the particular namespace for the Security object and the UsernameToken object. I can't seem to figure out how to override the default values supplied.
<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>
Here is the Python Code to generate the above
security = Security()
token = UsernameToken('CABLE', 'CABLE')
security.tokens.append(token)
client.set_options(wsse=security)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了。这就是答案。只需使用 ns 参数
Figured it out. Here is the answer. Just need to use the ns argument