404 using cherrypy.tree.mount
John Stile <[email protected]>
| Newsgroups | gmane.comp.python.cherrypy |
|---|---|
| Message-ID | <[email protected]> |
I am using CherryPy-5.3.0, mod_wsgi-4.4.21, and apache-2.4
When I use cherrypy.Application(), I get the expected response.
I want to migrate to using cherrypy.tree.mount(), but I always see 404.
myproject.wsgi (attached) has a function get_app(), where I try to use
either cherrypy.Application() or cherrypy.tree.mount() by commenting and
uncommenting.
In case it matters, my apache config:
WSGIScriptAlias /cherrypy
/var/www/localhost/wsgi/project_cherrypy/myproject.wsgi
<Directory "/var/www/localhost/wsgi/project_cherrypy">
AllowOverride None
Options None
Require all granted
</Directory>
Logs when I use cherrypy.tree.mount():
==> /var/log/apache2/error_log <==
[Mon May 02 21:15:06.429073 2016] [wsgi:info] [pid 18153] [client
::1:51425] mod_wsgi (pid=18153, process='',
application='localhost|/cherrypy'): Reloading WSGI script
'/var/www/localhost/wsgi/project_cherrypy/myproject.wsgi'.
==> /var/log/apache2/access_log <==
::1 - - [02/May/2016:21:15:06 -0700] "GET /cherrypy/joe/ HTTP/1.1" 404 745
==> logs/access.log <==
::1 - - [02/May/2016:21:15:06] "GET /cherrypy/joe/ HTTP/1.1" 404 745 ""
"Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
Logs when I use cherrypy.Application() :
==> /var/log/apache2/error_log <==
[Mon May 02 22:00:50.174465 2016] [wsgi:info] [pid 18154] [client
::1:51788] mod_wsgi (pid=18154, process='',
application='localhost|/cherrypy'): Reloading WSGI script
'/var/www/localhost/wsgi/project_cherrypy/myproject.wsgi'.
==> /var/log/apache2/access_log <==
::1 - - [02/May/2016:22:00:50 -0700] "GET /cherrypy/joe/ HTTP/1.1" 200 9
==> logs/access.log <==
::1 - - [02/May/2016:22:00:50] "GET /cherrypy/joe/ HTTP/1.1" 200 9 ""
"Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
myproject.wsgi
(text/x-python, 1.4 KB)
import os
import sys
# Apache base for the app
here = os.path.dirname(__file__)
# Activate virtualenv
activate_this = os.path.join( here, 'venv', 'bin','activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
# Add to python path
sys.path.insert(0,here)
# Not sure about this one
sys.stdout = sys.stderr
# Base module
import cherrypy
cherrypy.config.update({'environment': 'embedded'})
@cherrypy.popargs('name')
class Root(object):
@cherrypy.expose
def index(self, name):
return 'Hello {}'.format(name)
conf = {
'/': {
'log.access_file' : os.path.abspath(os.path.join( os.path.dirname(__file__),'logs','access.log')),
'log.error_file' : os.path.abspath(os.path.join( os.path.dirname(__file__),'logs','error.log')),
'tools.staticdir.root' : os.path.abspath(os.path.dirname(__file__)),
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')],
}
}
def get_app(config=None):
# This works
#return cherrypy.Application(Root(), script_name=None, config=conf)
# This responds wiht 404
cherrypy.config.update(config)
cherrypy.tree.mount(Root(),script_name='' ,config=config)
return cherrypy.tree
application = get_app(config=conf)
if __name__ == '__main__':
# when run as script, outside apache
cherrypy.quickstart(Root(), '/', conf)