Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import suds
- import datetime
- from suds.plugin import MessagePlugin
- PORT = "443"
- SERVICE = "/hpio/controller/soap/v6?wsdl" #change this to your webservice URL
- TRANSPORT = "https://"
- URL = "{0}{1}:{2}{3}"
- #Class to pass the type of passwd to the envelop
- class MyPlugin(MessagePlugin):
- def marshalled(self, context):
- header = context.envelope.getChild('Header')
- usertoken = header[0].getChild('UsernameToken')
- passwd = usertoken.getChild('Password')
- passwd.set('Type','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')
- #Class to create the connection
- class Connection(object):
- '''
- classdocs
- '''
- def __init__(self, server, username, password):
- '''
- Constructor
- '''
- endpoint = URL.format(TRANSPORT, server, PORT, SERVICE)
- self.client = suds.client.Client(url=endpoint, plugins=[MyPlugin()])
- security = suds.wsse.Security()
- token = suds.wsse.UsernameToken(username, password)
- security.tokens.append(token)
- security.tokens.append(suds.wsse.Timestamp())
- self.client.set_options(wsse=security, autoblend = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement