Skip to content Skip to sidebar Skip to footer

Typeerror: 'str' Object Is Not Callable When Using Cherrypy 3.2 Basic Authentication

My site configures CherryPy by way of a configuration file. In the configuration file I am trying to setup basic authentication. I have specified the fully qualified path to a 'c

Solution 1:

CherryPy config options are always regular python values. If you want to describe a module variable, you have to find a way to import it into the config file.

[/]tools.auth_basic.on = Truetools.auth_basic.realm = "some site"tools.auth_basic.checkpassword = __import__("Infrastructure.App.Authentication").App.Authentication.FindPassword

Edit: It looks like cherrypy's option parser chokes on the import keyword; you'll have to use the even longer, even less DRY form like this.

Edit2: the next problem you have is a missing self parameter. Change your authentication class to this:

classAuthentication:
    defFindPassword(self, realm, username, password):
        #            ^^^^^print realm
        print username
        print password
        return"password"

Solution 2:

The solution!

First, fix the config file like this. Remove the quotes from the function name:

tools.auth_basic.checkpassword =  Infrastructure.App.Authentication.FindPassword

Second, add the @staticmethod keyword to the checkpassword function:

@staticmethoddefFindPassword(realm, username, password):
    print realm
    print username
    print password
    return"password"

Post a Comment for "Typeerror: 'str' Object Is Not Callable When Using Cherrypy 3.2 Basic Authentication"