python - 'classobj' object is not subscriptable -


i following error while calling class-method using self.methodname() inside class method.

typeerror: 'classobj' object not subscriptable 

what problem be? other methods running fine except one. code details are

class loadbalancer:     def __init__(self):         #somecode     def upload_config(self,loadbalancer_doc)         #some code     def create_loadbalancer(self,loadbalancer_doc)         self.upload_config(loadbalancer_doc)#trace shows here error 

here upload_config method:

def upload_config(self,loadbalancer_doc):     no_of_ports=len(loadbalancer_doc['frontend_ports'])         loadbalancer_config=''     in range(0, no_of_ports):         servers=''         server_uuid in loadbalancer_doc['backend_servers']:             ip='192.168.1.1'             server_id=self.vms_collection.find_one({'_id':server_uuid}, {'id':1})['id']             servers=servers+'\tserver '+server_id+' '+ip+':'+loadbalancer_doc['backend_ports'][i]\                     +' check port '+loadbalancer_doc['check_port']+' inter '+loadbalancer_doc['check_interval']+'\n'         loadbalancer_config=loadbalancer_config+'listen '+loadbalancer_doc['_id']+\                             str(i)+'\n\tbind '+loadbalancer_doc['frontend_ip']+':'+loadbalancer_doc['frontend_ports'][i]\                             +'\n\toption '+loadbalancer_doc['check_protocol']+' '+loadbalancer_doc['check_protocol_param']+'\n'+servers+'\n'      open(local_dir+loadbalancer_doc['_id'], 'w') f:         f.write(loadbalancer_config)     try:             filenames=self.loadbalancer_collection.find({'destroyed_time':0})     except exception,err:         os.remove(local_dir+loadbalancer['_id'])         raise(err)     if not(filenames):         os.remove(local_dir+loadbalancer['_id'])         raise exception('no cursor returned')     configfiles=''     file in filenames:         configfiles=configfiles+' -f '+remote_config_file+file['_id']      try:         self._put_file(local_dir+loadbalancer_doc['_id'],remote_config_file+loadbalancer_doc['_id'])     except exception,err:         os.remove(local_dir+loadbalancer['_id'])         raise exception('copying config file remote server failed'+str(err))      try:         self._exec_command('haproxy'+\                                    ' -f /etc/haproxy/haproxy.cfg'+configfiles+\                                    ' -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)')     except exception,err:         os.remove(local_dir+loadbalancer['_id'])         #command_op=commands.getstatusoutput('ssh -i '+ssh_keyfile+' '+ssh_login+' rm '+remote_config_file+loadbalancer_doc['_id'])         raise exception('haproxy restart failed, err: '+str(err)) 

you have like:

balancer = loadbalancer balancer.create_loadbalancer(...) 

unlike c++, need parentheses when creating object if __init__ takes no arguments:

balancer = loadbalancer() balancer.create_loadbalancer(...) 

in former case, balancer class object, not object of class.

edit:

these lines cause problem:

    except exception,err:         os.remove(local_dir+loadbalancer['_id'])         raise(err)     if not(filenames):         os.remove(local_dir+loadbalancer['_id'])         raise exception('no cursor returned') 

what trying loadbalancer['_id']?


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -