[updated]: Full code
I always get confused with pyhton's staticmethods but according to this (last answer), it should work!
getting error:
AttributeError: class MyConnection has no attribute 'myuser'
class MyConnection: def __init__(self, hostname, port, user, password): myhostname = hostname myport = port myuser = user mypassword = password isisessid = None @staticmethod def connect(): my_session = MyConnection() headers = {'content-type': 'application/json'} headers['Authorization'] = 'Basic ' + string.strip( base64.encodestring(MyConnection.myuser + ':' + MyConnection.mypassword)) body = json.dumps({'username': MyConnection.myuser, 'password': MyConnection.mypassword, 'services': ['platform', 'namespace']}) uri = '/session/1/session' connection = httplib.HTTPSConnection(MyConnection.myhostname, MyConnection.myport) connection.connect() try: connection.request('POST', uri, body, headers) response = connection.getresponse() my_session.isisessid = MyConnection.extract_session_id( response.getheaders()) except Exception, e: print e connection.close() except httplib.BadStatusLine, e: print e connection.close() return my_session
__init__: stackoverflow.com/a/18622179/429533