Returning Cherripa NotFound: (404, "Path" / "Not Found".)

I am new to cherrypy and am trying to install a simple hello world app but it keeps returning "NotFound: (404," Path "/" not found. ")" But I defined it.

This is what I got,

In __ 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've tried with both decorator and index. exposed = True to no avail (question about which is the preferred method for cherry 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.

change

Here is the complete 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.")

      

+3


source to share


2 answers


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



cherrypy.engine.start()
cherrypy.engine.block()

      

+4


source


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



cherrypy.tree.mount(HomeNetMain(), "/", "main.cfg")

      

0


source







All Articles