Issue #888 resolved

fcgi wsgi bug: cherrypy.tree.mount looks for not yet existing wsgi_environ dict

Anonymous created an issue

I have been trying to deploy CherryPy in a shared hosting fcgi environment with flup

{{{flup.server.fcgi.WSGIServer(cherrypy_tree_mount).run()}}}

The problem is wsgi.fcgi (name of the fcgi script) is still in the url path. When I go to http://mysite.com/ expecting the root objects index method to be published I get this error

{{{NotFound: (404, "The path '/wsgi.fcgi/' was not found.")}}}

Puzzlingly, when running a simple wsgi function that dumps the environ:

{{{
...
'PATH_INFO': '/',              <--- This is normal
'QUERY_STRING': '',
'REDIRECT_STATUS': '200',
'REDIRECT_URL': '/',
'REQUEST_METHOD': 'GET',
'REQUEST_URI': '/',    
...
}}}

request.path_info is determined by: path[len(script_name):]

If request.app.script_name is {{{''}}} then will get errors: {{{NotFound: (404, "The path '/wsgi.fcgi/' was not found.")}}}

Only when an Application's script_name is excplicitly set to None will it look in the wsgi_environ dict for the SCRIPT_NAME

{{{root = cherrypy.Application(Root(), script_name=None)}}}

Problem is the app.script_name property is checked when using tree.mount

{{{app = cherrypy.tree.mount(root)}}}

cherrypy.tree.mount, if script_name is None, will check for the non existing, at this point, request.wsgi_environ

WORKAROUND:

This is the workaround I'm using at the moment

{{{
cherrypy.request.wsgi_environ = {'SCRIPT_NAME': __file__ }

root = cherrypy.Application(Root(), script_name=None)
app = cherrypy.tree.mount(root)
}}}

Reported by ndudfield@gmail.com

Comments (3)

  1. Robert Brewer

    Okay. Agreed that `Application(root, script_name=None)` should work, but using such an Application with Tree.mount doesn't make much sense, since cherrypy.tree is nothing more than a WSGI dispatcher based on script_name.

    As I see it, we have two options. A "purist" approach would say, "don't use cherrypy.tree; instead, attach your Application to a WSGI server interface directly". Since cherrypy.Application instances are WSGI applications, this could work. A more practical approach might be to allow a single Application to be hooked in at `Tree.apps[None]` and function as a default if none of the other Tree.apps match.

  2. Log in to comment