【问题标题】:how to omit tns from response and change tag name in spyne?如何从响应中省略 tns 并更改 spyne 中的标签名称?
【发布时间】:2018-07-19 10:51:50
【问题描述】:

如何在我的回复中省略 tns 并更改标签名称。? 我的回复是这样的

<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="spyne.example">
  <soap11env:Body>
    <tns:FnSchedule_CityResponse>
      <tns:FnSchedule_CityResult>
        <tns:ErrorString></tns:ErrorString>
        <tns:CityName>HYDERABAD</tns:CityName>
        <tns:CityId>1</tns:CityId>
        <tns:ErrId>0</tns:ErrId>
      </tns:FnSchedule_CityResult>
    </tns:FnSchedule_CityResponse>
  </soap11env:Body>
</soap11env:Envelope>

我想删除 tns 并将“soap11env”更改为“soap”。 拥有这些值会导致验证问题。

我在堆栈溢出时提到了这个问题,实现了它,但没有帮助。 Remove the namespace from Spyne response variables

【问题讨论】:

    标签: python python-2.7 spyne


    【解决方案1】:

    为了将soap11env更改为soap,只需简单地使用覆盖响应

    application.interface.nsmap['soap'] = application.interface.nsmap['soap11env']
    

    “tns”或目标命名空间不得更改,但可能会出现一些情况,可能需要更改名称才能完全测试某些内容。

    要更改命名空间,

    def on_method_return_string(ctx):
    ctx.out_string[0] = ctx.out_string[0].replace(b'ns4', b'diffgr')
    ctx.out_string[0] = ctx.out_string[0].replace(b'ns5', b'msdata')
    

    YourModelClassName.event_manager.add_listener('method_return_string', on_method_return_string)

    我在这里所做的是,将命名空间 ns4 替换为 diffgr,将 ns5 替换为 msdata。 ns4 和 ns5 是我在某些第三方应用程序的响应中拥有的子名称空间。我在为 spyne 维护的邮件列表中找到了这个解决方案。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-21
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-19
    • 2011-03-27
    • 1970-01-01
    相关资源
    最近更新 更多