How to pass SOAP headers into python SUDS that are not defined in WSDL file
来源:互联网 发布:域名备案的好处 编辑:程序博客网 时间:2024/05/17 03:17
I have a camera on my network which I am trying to connect to with suds but suds doesn't send all the information needed. I need to put extra soap headers not defined in the WSDL file so the camera can understand the message. All the headers are contained in a SOAP envelope and then the suds command should be in the body of the message.
I have checked the suds website and it says to pass in the headers like so: (This passes in the element as a header but I have an envelope so I'm not sure how to input this)
from suds.sax.element import Elementclient = client(url)ssnns = ('ssn', 'http://namespaces/sessionid')ssn = Element('SessionID', ns=ssnns).setText('123')client.set_options(soapheaders=ssn) result = client.service.addPerson(person)
Now, I am not sure how I would implement this. Say for example, I have the below header:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAPENC="http://www.w3.org/2003/05/soap-encoding"<wsa:MessageID SOAP-ENV:mustUnderstand="true">urn:uuid:43268c01-f09c6</wsa:MessageID> <SOAP-ENV:Header>
Using this or a similar example does anyone know how I would get this passed into the soap command so my camera understands?
Thanks
1 Answer
I have worked out how to enter in new headers and namespaces in suds. As stated above you create an Element and pass it in as a soapheader as so:
from suds.sax.element import Element client = client(url) ssnns = ('ssn', 'http://namespaces/sessionid') ssn = Element('SessionID', ns=ssnns).setText('123') client.set_options(soapheaders=ssn) result = client.service.addPerson(person)
But if you would like to add a namespace I have found adding a prefix seem's to do the trick. So when you create one of the elements you add addPrefix
. I'm not sure if this was the way it was intended to be done but it work's.
ssn = Element('SessionID', ns=ssnns).setText('123').addPrefix(p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding')
The p = 'SOAP-ENC'
can be any prefix eg. wsa
and the u = http://address
is the address of the namespace.
A complete script that would run could be:
#!/usr/local/bin/python2.6import suds#import loggingfrom suds.client import Clientfrom suds.sax.element import Elementfrom suds.sax.attribute import Attributefrom suds.xsd.sxbasic import Importdef absoluteMove(): # connects to WSDL file and stores location in variable 'client' client = Client('http://10.10.10.10/p.wsdl') client.options.location = 'http://10.10.10.10:32963' # Create the header wsans = ('wsa', 'http://schemas.xmlsoap.org/ws/2004/08/addressing') mustAttribute = Attribute('SOAP-ENV:mustUnderstand', 'true') n1s = ('SOAP-ENC', 'http://www.w3.org/2003/05/soap-encoding') msgId = Element('Element').addPrefix(p='SOAP-ENC', u='http://www.w3.org/2003/05/soap-encoding') msgId2 = Element('Address', ns=wsans).setText('http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous') msgId1 = Element('ReplyTo', ns=wsans).insert(msgId2) msgId1.append(mustAttribute) msgId3 = Element('To', ns=wsans).setText('http://10.10.10.10:32954') msgId3.append(mustAttribute) client.set_options(soapheaders=[msgId, msgId1, msgId3, msgId2]) # Create 'token' object to pass as an argument using the 'factory' namespace token = client.factory.create('ns4:ReferenceToken') # Create 'dest' object to pass as an argument and values passed to this object dest = client.factory.create('ns4:PTZVector') dest.PanTilt._x=1 dest.PanTilt._y=4.9 dest.Zoom._x=1 # Create 'speed' object to pass as an argument and values passed to this object speed = client.factory.create('ns4:PTZSpeed') speed.PanTilt._x=0 speed.PanTilt._y=0 speed.Zoom._x=1 # 'AbsoluteMove' method invoked passing in the new values entered in the above objects try: result = client.service.AbsoluteMove(token, dest, speed) print "absoluteMove result ", result return result except suds.WebFault, e: print "suds.WebFaults caught: " print eif __name__ == '__main__': result = absoluteMove()
This moves the camera. To change the type of soap-envelope check my next question.
You can add logging into this script whci allow's you to check what xml command you have sent which is handy:
import logginglogging.basicConfig(level=logging.INFO)logging.getLogger('suds.client').setLevel(logging.DEBUG)
The location can be put into the script as an option if the location is not in the wsdl file.
- How to pass SOAP headers into python SUDS that are not defined in WSDL file
- How to express that you are unhappy.
- How to pass arguments in exchange
- How to find child controls that are located in the template of a parent control
- How can I force WebLogic to use third party jars that are included in my Ear?
- How to access a value defined in the application.properties file in Spring Boot ( Externalized Conf)
- An attempt was made to set a report parameter that is not defined in this report
- [Python] How to Open Zip File in Host Location.
- How to reference JSF managed beans which are provided in a JAR file?
- Parcelable - How to do that in Android
- How to overcome “datetime.datetime not JSON serializable” in python?
- Troubleshooting High I/O Wait in Linux --- A walkthrough on how to find processes that are causing h
- 错误 the type "xxxx" is defined in an assembly that is not refernced.You must add a reference to assem
- Studying python/SOAP/WSDL
- Item41 Consider pass by value for copyable parameters that are cheap to move and always copied.
- How to sort by a form that is not displayed in the document in MicroStrategy Desktop 8.x
- HTTP Error 401.2 - You are not authorized to view this page due to invalid authentication headers
- How to pass the paramater of Node.js or io.js into native C/C++ function.
- TCPMP-interface相关文件函数解析-Mediainfo.c
- poj 1384 Piggy-Bank(完全背包)
- 你还好么
- 全智贤夫妇恩爱秘诀被公开 做好"贤内助"有一套
- 外媒:李克强非洲行掀起“中国旋风”
- How to pass SOAP headers into python SUDS that are not defined in WSDL file
- 付款的话会离开萨丹哈了卡死了和
- java socket读数据阻塞解决办法
- 当地时间5月13日,Chanel 2015早春
- mysql 查询技巧
- otsu(大津法)灰度图像二值化方法的原理和C实现
- 彻底删除的文件也能找回
- 同一个商品有多个条码怎么录入?
- 雷霆怎么招惹你们了