TypeError: unbound method “method name” must be called with “Class name” instance as first argument (got str instance instead)

后端 未结 1 1744
余生分开走
余生分开走 2021-02-05 20:50

I think this should be a simple question to answer.

I have the next classes:

class GruposHandler(webapp.RequestHandler):
    def get(self):
        self.         


        
相关标签:
1条回答
  • 2021-02-05 21:18
    grupoHandler = GruposHandler
    

    ==>

    grupoHandler = GruposHandler()
    

    UPDATE:

    GruposHandler.obtenerPagina() method accepts 3 arguments:
    self, pOpcion=None and pMensajeInformacion=None.

    Since 2 of them are optional, you don't get:

    TypeError: ... takes exactly 3 arguments (2 given)
    

    when calling it like this:

    GruposHandler.obtenerPagina("gruposMios", 'Informacion: ...')
    

    Instead GruposHandler.obtenerPagina() interprets arguments like this:

    self="gruposMios", pOpcion='Informacion: ...', pMensajeInformacion=None
    

    and raises:

    TypeError: ... must be called with instance (got str instance instead)
    

    To get rid of the exception, you need to call this method from instance:

    GruposHandler().obtenerPagina("gruposMios", 'Informacion: ...')
    

    and self will be passed to obtenerPagina implicitly.

    0 讨论(0)
提交回复
热议问题