Cherrypy作为windows服务。找不到路径

时间:2015-01-12 12:12:28

标签: python windows-services cherrypy

我已经设法让我的(烧瓶)应用程序运行像cherrypy一样运行wsgi服务器:

from mypyapp import app
import cherrypy

if __name__ == '__main__':
    cherrypy.tree.graft(app, "/")
    cherrypy.config.update({
        'log.screen': True,
        'server.socket_port': 8888,
    })
    cherrypy.engine.start()
    cherrypy.engine.block()

现在我正在尝试将其安装为Windows服务,但我遇到了问题。这是代码:     进口樱桃     来自mypyapp导入应用程序

class PyWebService(win32serviceutil.ServiceFramework):
    """ Py Web Service """

    def SvcDoRun(self):
        cherrypy.tree.mount(app, "/")

        cherrypy.config.update({
            'global': {
            'engine.autoreload.on': False,
            'log.screen': False,
            'log.error_file': 'c:\\Temp\\error.log',
            'engine.SIGHUP': None,
            'engine.SIGTERM': None,
            'server.socket_port': 8888,
        }
        })

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

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        cherrypy.engine.exit()
        self.ReportServiceStatus(win32service.SERVICE_STOPPED)

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(ConcertWebService)

我可以在日志中安装并运行服务和输出,表明它正在运行而没有任何问题。但是当我尝试使用浏览器访问服务器时,我得到了404

404 Not Found

The path '/' was not found.

Traceback (most recent call last):
  File "C:\Users\viktor.forsman\IdeaProjects\cfas\venv\lib\site-packages\cherrypy\_cprequest.py", line 670, in respond
    response.body = self.handler()
  File "C:\Users\viktor.forsman\IdeaProjects\cfas\venv\lib\site-packages\cherrypy\lib\encoding.py", line 217, in __call__
self.body = self.oldhandler(*args, **kwargs)
  File "C:\Users\viktor.forsman\IdeaProjects\cfas\venv\lib\site-packages\cherrypy\_cperror.py", line 411, in __call__
   raise self
NotFound: (404, "The path '/' was not found.") 

我无法理解配置中的差异。任何想法都非常欢迎!

1 个答案:

答案 0 :(得分:0)

好的,我觉得很蠢。在我的服务模块中,我做了:

cherrypy.tree.mount(app, "/")

将其更改为:

cherrypy.tree.graft(app, "/")

它有效。