Advertisement
gnuowned

connection

May 5th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import suds
  2. import datetime
  3. from suds.plugin import MessagePlugin
  4.  
  5. PORT = "443"
  6. SERVICE = "/hpio/controller/soap/v6?wsdl"  #change this to your webservice URL
  7. TRANSPORT = "https://"
  8. URL = "{0}{1}:{2}{3}"
  9.  
  10. #Class to pass the type of passwd to the envelop
  11. class MyPlugin(MessagePlugin):
  12.     def marshalled(self, context):
  13.         header = context.envelope.getChild('Header')
  14.         usertoken = header[0].getChild('UsernameToken')
  15.         passwd = usertoken.getChild('Password')
  16.         passwd.set('Type','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText')
  17.  
  18. #Class to create the connection
  19. class Connection(object):
  20.     '''
  21.     classdocs
  22.     '''
  23.     def __init__(self, server, username, password):
  24.         '''
  25.         Constructor
  26.         '''
  27.                        
  28.         endpoint = URL.format(TRANSPORT, server, PORT, SERVICE)
  29.         self.client = suds.client.Client(url=endpoint, plugins=[MyPlugin()])
  30.         security = suds.wsse.Security()
  31.         token = suds.wsse.UsernameToken(username, password)
  32.             security.tokens.append(token)
  33.         security.tokens.append(suds.wsse.Timestamp())
  34.         self.client.set_options(wsse=security, autoblend = True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement