如何从响应中省略 tns 并在 spyne 中更改标签名称?

how to omit tns from response and change tag name in spyne?

如何从我的回复中省略 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"。 拥有这些值会导致验证问题。

我在堆栈溢出上提到了这个问题,实现了它,但没有帮助。

为了将 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 维护的邮件列表中找到了这个解决方案。