python suds UsernameToken

时间:2016-05-28 16:29:04

标签: python soap suds

代码:

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>

我怎么能用肥皂水呢?搜索了整个互联网,但没有找到解决方案。

1 个答案:

答案 0 :(得分:0)

您的代码是SOAP通用解决方案。您的网络服务似乎需要自定义响应。

我认为你的身份验证不起作用?

尝试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