python suds用户名令牌

2024-05-19 10:23:25 发布

您现在位置:Python中文网/ 问答频道 /正文

代码:

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

我的问题是:当包含UsernameToken时,我会收到这样的头:

^{pr2}$

但我需要的是对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>

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


Tags: 代码orgtokenhttpwspolicyschemassp
1条回答
网友
1楼 · 发布于 2024-05-19 10:23:25

您的代码是一个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

相关问题 更多 >

    热门问题