Python Suds 用户名令牌。

4

代码:

security = Security()
token = UsernameToken('b77a5c561934e089', 'kmfHkNZyn1U/pGAiY3+h0BoHdKI=')
security.tokens.append(token)
client.set_options(wsse=security)

我的问题是:当包含UsernameToken时,我收到了这样的头部信息:
   <SOAP-ENV:Header>
      <wsse:Security mustUnderstand="true">
         <wsse:UsernameToken>
            <wsse:Username>b77a5c561934e089</wsse:Username>
            <wsse:Password>kmfHkNZyn1U/pGAiY3+h0BoHdKI=</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </SOAP-ENV:Header>

但我需要的是对Web服务需求的响应:

<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
  <wsp:Policy>
    <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
      <wsp:Policy>
        <sp:WssUsernameToken10 />
      </wsp:Policy>
    </sp:UsernameToken>
  </wsp:Policy>
</sp:SignedSupportingTokens>

我该如何使用suds实现这个功能?我在网上搜了半天,都没有找到解决方案。

1个回答

0

你的代码是一个SOAP通用解决方案。你的Web服务似乎需要一个定制响应。

我猜测你的身份验证不起作用了?

尝试将你的响应marshall到你的请求者class中。这个plugin允许你修改你的soap信封。你可以添加自己的属性。

class MyRequesterClass(object):

    class _myServiceMarshalled(MessagePlugin):

        def marshalled(self, context):
            commons.set_service_common_header(context, "yourService")

            body = context.envelope.getChild('Body')
            service = body.getChild("childWhereYouWantAddYourCustomXML")

            service.attributes.append(Attribute("sp:IncludeToken", "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"))

            etc, etc

在这个例子中,“commons”是什么? - anddam

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接