Hello,
I'm trying to adapt https://github.com/conover/BBLearnWS/blob/master/demo.pythis script to my webservice because I need add a type tag on WSSE.
Below is my script:
#!/usr/bin/python from suds.client import * from suds.wsse import * from suds.plugin import Plugin from suds.sax.element import Element
url = 'file:///Webservice.wsdl' #client = Client(url) security = Security() class TypePlugin(Plugin): def sending(self, context): password = context.envelope.childAtPath('Header/Security/UsernameToken/Password') password.set('Type', 'Type= http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profi... ')
token = UsernameToken('myuser', 'mypasswd') security.tokens.append(token)
client = Client(url) client.set_options(wsse=security, autoblend = True, plugins = [TypePlugin()])
import logging logging.basicConfig(level=logging.INFO) logging.getLogger('suds.client').setLevel(logging.DEBUG) logging.getLogger('suds.transport').setLevel(logging.DEBUG)
print client.service.ContactQueryPage()
Abaixo output:
[danilo@napmon01 crm]$ python webservice.py DEBUG:suds.client:sending to ( https://secure-ausomxkwa.crmondemand.com/Services/Integration) message: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:ns0="urn:crmondemand/ws/ecbs/contact/10/2004" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1...." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/%22%3E SOAP-ENV:Header <wsse:Security mustUnderstand="true"> wsse:UsernameToken wsse:Usernamemyuser</wsse:Username> wsse:Passwordmypasswd</wsse:Password> </wsse:UsernameToken> </wsse:Security> </SOAP-ENV:Header> ns1:Body ns0:ContactQueryPage_Input ns0:ListOfContact/ </ns0:ContactQueryPage_Input> </ns1:Body> </SOAP-ENV:Envelope> DEBUG:suds.client:headers = {'SOAPAction': '"document/urn:crmondemand/ws/ecbs/contact/10/2004:ContactQueryPage"', 'Content-Type': 'text/xml; charset=utf-8'} DEBUG:suds.transport.http:sending: URL:https://secure-ausomxkwa.crmondemand.com/Services/Integration HEADERS: {'SOAPAction': '"document/urn:crmondemand/ws/ecbs/contact/10/2004:ContactQueryPage"', 'Content-Type': 'text/xml; charset=utf-8', 'Content-type': 'text/xml; charset=utf-8', 'Soapaction': '"document/urn:crmondemand/ws/ecbs/contact/10/2004:ContactQueryPage"'} MESSAGE: <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:ns0="urn:crmondemand/ws/ecbs/contact/10/2004" xmlns:ns1=" http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1...." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/%22%3ESOAP-ENV:Headerwsse:Security mustUnderstand="true"wsse:UsernameTokenwsse:UsernameCVCBRASIL/MONITOR</wsse:Username>wsse:Passwordcvc123monitor</wsse:Password></wsse:UsernameToken></wsse:Security></SOAP-ENV:Header>ns1:Bodyns0:ContactQueryPage_Inputns0:ListOfContact/</ns0:ContactQueryPage_Input></ns1:Body></SOAP-ENV:Envelope> ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:ns0="urn:crmondemand/ws/ecbs/contact/10/2004" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse=" http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1...." xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/%22%3E SOAP-ENV:Header <wsse:Security mustUnderstand="true"> wsse:UsernameToken wsse:Usernamemyuser</wsse:Username> wsse:Passwordmypasswd</wsse:Password> </wsse:UsernameToken> </wsse:Security> </SOAP-ENV:Header> ns1:Body ns0:ContactQueryPage_Input ns0:ListOfContact/ </ns0:ContactQueryPage_Input> </ns1:Body> </SOAP-ENV:Envelope> DEBUG:suds.client:http failed: <?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/%22%3Esoap:Bodysoap:Fault<faultcode>soap:Client</faultcode><faultstring>Client</faultstring><detail><ErrorCode>SBL-ODU-01008</ErrorCode><ErrorMessage>The HTTP request did not contain well-formed XML. An attempt to parse it produced the following error: wsse:Password must specify a Type.</ErrorMessage></detail></soap:Fault></soap:Body></soap:Envelope> Traceback (most recent call last): File "check_crm.py", line 25, in ? print client.service.ContactQueryPage() File "/usr/lib/python2.4/site-packages/suds/client.py", line 542, in __call__ return client.invoke(args, kwargs) File "/usr/lib/python2.4/site-packages/suds/client.py", line 602, in invoke result = self.send(soapenv) File "/usr/lib/python2.4/site-packages/suds/client.py", line 657, in send result = self.failed(binding, e) File "/usr/lib/python2.4/site-packages/suds/client.py", line 718, in failed raise Exception((status, reason)) Exception: (400, u'Bad Request')
Any idea how I can specify the Type?
Thanks