5

I am new to cherrypy and am trying to mount a simple hello world application but it keeps returning "NotFound: (404, "The path '/' was not found.")", but I have defined it.

Here's what I got,

In the __init__.py

import cherrypy
from HomeNetMain import HomeNetMain

cherrypy.config.update("global.cfg")
#I have tried "" for the script name parm but that doesn't work
cherrypy.tree.mount(HomeNetMain,"/","main.cfg") 
cherrypy.engine.start()
cherrypy.quickstart()

In another file I have

import cherrypy

class HomeNetMain:

    @cherrypy.expose
    def index(self):
       return "Hello World"

I have tried with both the decorator and index.exposed=True to no avail (sub question what is the preferred method for cherrypy the decorator or index.exposed)

global.cfg

[global]
server.socket_host: "127.0.0.1"
server.socket_port: 9080
log.screen: True
log.error_file: "/tmp/cherrypy.error"
log.access_file: "/tmp/cherrypy.access"

main.cfg

[/]
log.screen: True
log.error_file: "/tmp/homenet.error"
log.access_file: "/tmp/homenet.access"

I appreciate any help, thanks in advance.

edit

Here is the full stacktrace

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cperror.py", line 386, in __call__
raise self
NotFound: (404, "The path '/' was not found.")
mitchellsg
  • 486
  • 5
  • 13

2 Answers2

4

Turns out I shouldn't have been using cherrypy.quickstart() I changed the code to the following and it worked fine

cherrypy.engine.start()
cherrypy.engine.block()
mitchellsg
  • 486
  • 5
  • 13
  • 1
    i'm using this currently `cherrypy.quickstart(Control(), config=tutconf)` how to change to the above mention? – yvonnezoe Mar 16 '14 at 16:07
0

The class HomeNetMain is being mounted, instead of the instance. Since index is not a classmethod, a TypeError will be thrown which the framework is handling as 404.

cherrypy.tree.mount(HomeNetMain(), "/", "main.cfg")
A. Coady
  • 54,452
  • 8
  • 34
  • 40
  • Thanks for the update but that doesn't appear to be the problem after changing it I am still get a 404 I'll add the full stacktrace to the question – mitchellsg Apr 02 '12 at 22:26