TypeError: 'int' object is not callable

AWasilenko at gmail.com AWasilenko at gmail.com
Thu Mar 22 21:28:11 EDT 2007


On Mar 22, 8:59 pm, "Dan Bishop" <danb... at yahoo.com> wrote:
> On Mar 22, 6:54 pm, AWasile... at gmail.com wrote:
>
>
>
>
>
> > I'm trying to test a few different approaches to displaying pages via
> > Cherrypy and I'm not having much luck.  Here is my code so far:
>
> > import sys, cherrypy, html
>
> > class Root:
> >         @cherrypy.expose
> >         def index(self, pageid = None):
> >                 selection = html.Page()
> >                 return  selection.input()
>
> > cherrypy.config.update({'server.socket_port': 2572, 'log.screen':
> > False})
> > cherrypy.quickstart(Root())
>
> > and here is the html.py file that I import:
>
> > class Page:
> >         def input(self,dex=None):
> >                 if dex == None:
> >                         return 404(dex)
> >                 else:
> >                         return "Something else?"
>
> >         def err404(self,whatitis="N/A"):
> >                 return """<body bgcolor="#666666">
> > <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
>
> > <center>Sorry the page: """ + str(whatitis) + """ does not exist.<br /
>
> > <img src="/files/images/404.png" alt="Page cannot be found."></center>
> > </body>"""
>
> > and here is the error I get when trying to run this:
>
> > 500 Internal Server Error
> > The server encountered an unexpected condition which prevented it from
> > fulfilling the request.
>
> > Traceback (most recent call last):
> >   File "/home2/awasilenko/lib/python2.4/cherrypy/_cprequest.py", line
> > 342, in respond
> >     cherrypy.response.body = self.handler()
> >   File "/home2/awasilenko/lib/python2.4/cherrypy/_cpdispatch.py", line
> > 15, in __call__
> >     return self.callable(*self.args, **self.kwargs)
> >   File "/home2/awasilenko/webapps/cp/site.py", line 7, in index
> >     return  selection.input()
> >   File "/home2/awasilenko/webapps/cp/html.py", line 4, in input
> >     return 404(dex)
> > TypeError: 'int' object is not callable
>
> > I know this isn't a Cherrypy issue since I have made other pages work,
> > I'm just making a dumb mistake somewhere.  My plan is to eventually be
> > able to pass dex to the input def in the page class so it can display
> > the right page.  Right now I am just trying to make ANY thing show up,
> > what should happen is since I'm not passing anything everything should
> > be None and the 404 page should pop up.  I would also like to make the
> > 404 page print the page that was requested, I have already coded the
> > return but have not "connected" it yet, one step at a time...
>
> 404 is an integer literal; you can't use it as a function name.- Hide quoted text -
>
> - Show quoted text -

I saw that 404 was turning colors in my editor when I used it, that's
why I changed the def name, I just forgot to change it in the input
def also.  Here is the working code now:

class Page:
	def input(self,dex=None):
		if dex == None:
			return self.err404(dex)
		else:
			return "Something else?"

	def err404(self,whatitis="N/A"):
		return """<body bgcolor="#666666">
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /
><br /><br />
<center>Sorry the page: """ + str(whatitis) + """ does not exist.<br /
>
<img src="/files/images/404.png" alt="Page cannot be found."></center>
</body>"""

Now I can work on getting the other stuff working.  I can't believe
something that stupid was holding me up, oh well :)




More information about the Python-list mailing list