简体   繁体   English

在Suds python中覆盖Soap Envelope

[英]Overwrite the Soap Envelope in Suds python

I have a camera and I am trying to connect to it vis suds. 我有一个相机,我正试图连接它与泡沫。 I have tried to send raw xml and have found that the only thing stopping the xml suds from working is an incorrect Soap envelope namespace. 我试图发送原始的xml,并发现阻止xml suds工作的唯一因素是不正确的Soap信封命名空间。

The envelope namespace is: 信封命名空间是:

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

and I want to rewrite it to: 我想把它重写为:

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

In order to add a namespace in python I try this code: 为了在python中添加命名空间,我尝试以下代码:

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

But when I add the SOAP-ENV to the namespace it doesn't write as it is hardcoded into the suds bindings. 但是当我将SOAP-ENV添加到命名空间时,它不会写入,因为它被硬编码到suds绑定中。 Is there a way to overwrite this in suds? 有没有办法在泡沫中覆盖这个?

Thanks for any help. 谢谢你的帮助。

I got around it by manually overriding the suds.binding.envns variable in the bindings module: 我通过手动覆盖bindings模块中的suds.binding.envns变量来解决它:

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

From here on, all goes well (with my service, that is) 从这里开始,一切顺利( 我的服务,即)

I managed to get this working, the soap envelope is hard coded into bindings.py that is stored in suds.egg installed in your site-packages. 我设法让这个工作,soap信封被硬编码到bindings.py ,存储在你的site-packages中安装的suds.egg中。 I changed the SOAP envelope address to http://www.w3.org/2003/05/soap-envelope . 我将SOAP信封地址更改为http://www.w3.org/2003/05/soap-envelope This was compatible with my camera. 这与我的相机兼容。 I was unable to find a command to overwrite this envelope in suds so I hard coded it in to the bindings.py. 我无法在suds中找到覆盖此信封的命令,因此我将其硬编码到bindings.py中。

Thanks for any help 谢谢你的帮助

Manually updating binding.py definitely isn't the right way to go. 手动更新binding.py肯定不是正确的方法。 You should be able to utilize the ImportDoctor to override your default bindings. 您应该能够利用ImportDoctor覆盖默认绑定。 Have a look at the documentation for fixing broken schemas on the Suds website. 在Suds网站上查看修复损坏模式的文档。

Also, what versions of Python and suds are you using? 另外,你使用的是什么版本的Python和suds?

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()])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM