#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-profile-1.0#PasswordText')
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.0.xsd" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<wsse:Security mustUnderstand="true">
<wsse:UsernameToken>
<wsse:Username>myuser</wsse:Username>
<wsse:Password>mypasswd</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.0.xsd" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><wsse:Security mustUnderstand="true"><wsse:UsernameToken><wsse:Username>CVCBRASIL/MONITOR</wsse:Username><wsse:Password>cvc123monitor</wsse:Password></wsse:UsernameToken></wsse:Security></SOAP-ENV:Header><ns1:Body><ns0:ContactQueryPage_Input><ns0: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.0.xsd" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<wsse:Security mustUnderstand="true">
<wsse:UsernameToken>
<wsse:Username>myuser</wsse:Username>
<wsse:Password>mypasswd</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/"><soap:Body><soap: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')