【问题标题】:Overwrite the Soap Envelope in Suds python在 Suds python 中覆盖肥皂信封
【发布时间】:2010-03-30 10:09:20
【问题描述】:

我有一个摄像头,我正在尝试连接它以防止产生泡沫。我尝试发送原始 xml,发现阻止 xml suds 工作的唯一原因是不正确的 Soap 信封命名空间。

信封命名空间是:

xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

我想把它改写成:

xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"

为了在 python 中添加命名空间,我尝试了以下代码:

message = Element('Element_name').addPrefix(p='SOAP-ENC', u='www.w3.org/ENC')

但是当我将 SOAP-ENV 添加到命名空间时,它不会写入,因为它是硬编码到 suds 绑定中的。有没有办法在 suds 中覆盖它?

感谢您的帮助。

【问题讨论】:

  • 你得到什么类型的错误?你能详细说明并发布你的代码吗?

标签: python xml soap suds envelope


【解决方案1】:

我通过手动覆盖bindings 模块中的suds.binding.envns 变量解决了这个问题:

from suds.bindings import binding
binding.envns=('SOAP-ENV', 'http://www.w3.org/2003/05/soap-envelope')

从这里开始,一切顺利(使用 my 服务)

【讨论】:

    【解决方案2】:

    我设法让这个工作,肥皂信封被硬编码到 bindings.py 中,存储在安装在您的站点包中的 suds.egg 中。我将 SOAP 信封地址更改为http://www.w3.org/2003/05/soap-envelope。这与我的相机兼容。我找不到在 suds 中覆盖这个信封的命令,所以我将它硬编码到 bindings.py 中。

    感谢您的帮助

    【讨论】:

    • 关于如何将标题输入到泡沫中,请查看我之前的问题。我会发布我的代码,因为我知道文档很少。
    【解决方案3】:

    手动更新binding.py 绝对不是正确的方法。您应该能够使用ImportDoctor 来覆盖您的默认绑定。在 Suds 网站上查看 fixing broken schemas 的文档。

    另外,您使用的是什么版本的 Python 和 suds?

    【讨论】:

      【解决方案4】:
      from suds.client import Client
      from suds.plugin import MessagePlugin
      
      WSDL_url = "my_url?wsdl"
      
      class MyPlugin(MessagePlugin):
          def marshalled(self, context):
              #print(str(context.envelope))
              context.envelope.nsprefixes['SOAP-ENV']='myText'
      
      client = Client(WSDL_url, plugins=[MyPlugin()])
      

      【讨论】:

      • 应该考虑这个答案。谢谢尼古拉!
      猜你喜欢
      • 2015-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多