TypeError: 'int' object is not callable

A

AWasilenko

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 "" said:
<br /><br /><br /><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...
 
D

Dan Bishop

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.
 
A

AWasilenko

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 "" said:
<br /><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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top