Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:20:46+00:00 2026-05-23T14:20:46+00:00

I get the following error while calling a class-method using self.methodname() from inside another

  • 0

I get the following error while calling a class-method using self.methodname() from inside another class method.

TypeError: 'classobj' object is not subscriptable

What could the problem be? Other methods are running fine except this 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 back shows here i get this error

here is the upload_config method:

def upload_config(self,loadbalancer_doc):
    no_of_ports=len(loadbalancer_doc['frontend_ports'])    
    loadbalancer_config=''
    for i in range(0, no_of_ports):
        servers=''
        for 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'

    with open(LOCAL_DIR+loadbalancer_doc['_id'], 'w') as 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=''
    for 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 to 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))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:20:47+00:00Added an answer on May 23, 2026 at 2:20 pm

    You probably have something like:

    balancer = loadbalancer
    balancer.create_loadbalancer(...)
    

    Unlike C++, you need the parentheses when creating an object even if __init__ takes no arguments:

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

    In the former case, balancer is the class object, not an object of the class.

    EDIT:

    These lines could cause a 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 are you trying to do with loadbalancer['_id']?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While calling a web service I get the following error: The HTTP request is
I get the following error while building OpenCV on OS X 10.5 (intel): ld:
while executing the following query, i get an error that there's an error in
In defining my Element class I get the following error: no matching function for
I am getting the following error using WCF, calling the a WCF Service on
I get following error when deploying on test server with II6 and Framework 3.5
Why do I get following error when trying to start a ruby on rails
We get the following error; The request was aborted: Could not create SSL/TLS secure
I get the following error when running my Visual Studio 2008 ASP.NET project (start
I get the following error when building my Windows Forms solution: LC.exe exited with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.