Overwrite the Soap Envelope in Suds python
Asked Answered
B

4

7

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.

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:

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. Is there a way to overwrite this in suds?

Thanks for any help.

Benevolent answered 30/3, 2010 at 10:9 Comment(1)
What type of error do you get?Could you elaborate and post your code?Ulysses
B
3

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. I changed the SOAP envelope address to 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.

Thanks for any help

Benevolent answered 30/3, 2010 at 14:22 Comment(1)
For how to enter header's into suds check out my previous question. I'll post my code as I know how little documentation there is.Benevolent
W
6

I got around it by manually overriding the suds.binding.envns variable in the bindings module:

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)

Wentworth answered 29/1, 2013 at 9:48 Comment(0)
B
3

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. I changed the SOAP envelope address to 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.

Thanks for any help

Benevolent answered 30/3, 2010 at 14:22 Comment(1)
For how to enter header's into suds check out my previous question. I'll post my code as I know how little documentation there is.Benevolent
R
1

Manually updating binding.py definitely isn't the right way to go. You should be able to utilize the ImportDoctor to override your default bindings. Have a look at the documentation for fixing broken schemas on the Suds website.

Also, what versions of Python and suds are you using?

Roturier answered 2/4, 2010 at 23:49 Comment(0)
C
1
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()])
Circumgyration answered 15/4, 2016 at 12:1 Comment(1)
This answer should be considered. Thank you Nikola!Sphenoid

© 2022 - 2024 — McMap. All rights reserved.