How to pass SOAP headers into python SUDS that are not defined in WSDL file
2014-05-14 17:09
701 查看
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 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) 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:SOAP ENC="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 python xml wsdl suds soapheader
| |||
add comment |
1 Answer
activeoldestvotesup vote11down voteaccepted | 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. wsaand the u = http://address[/code] is the address of the namespace. |
相关文章推荐
- file - How do I remove/delete a folder that is not empty with Python? - Stack Overflow
- How can I force WebLogic to use third party jars that are included in my Ear?
- [Tips] How to Add New field into Shapefile attribute table in ArcGIS ?
- Sharepoint Error : The URL "filename" is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web
- 使用cocapods报错 [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes
- How to sort by a form that is not displayed in the document in MicroStrategy Desktop 8.x
- The URL "filename" is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web
- 错误 the type "xxxx" is defined in an assembly that is not refernced.You must add a reference to assem
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- How to find child controls that are located in the template of a parent control
- How to avoid Excel from prompting "The file you are trying to open, , is in a different format than specified by the file extension"? (转)
- 错误 the type "xxxx" is defined in an assembly that is not refernced.You must add a reference to assem
- 转载:How (not) to set a timeout on a computation in Python
- How to overcome “datetime.datetime not JSON serializable” in python?
- EPLAN API 入门系列- 提高篇(How to get all connections which are not in location box)
- How to create MFC applications that do not have a menu bar in Visual C++(MFC单文档和多文档程序中去掉菜单栏)(转)
- An attempt was made to set a report parameter that is not defined in this report
- How to overcome “datetime.datetime not JSON serializable” in python?
- [Linux cmd line] How to convert a binary file into output in C include file style.
- How to fix "Resource file <C_PsdRsdll> not found" issue in Windows OS