Graham Dumpleton
graham.dumpleton at gmail.com
Thu Jul 30 19:00:59 EDT 2009
2009/7/31 Orr, Steve <sorr at rightnow.com>: > Running Apache 2.2.4; mod_python 3.3.1; Python 2.4. > > > > Experiencing behavioral problems with WSGI on mod_python. I’m running the > exact same code but mod_wsgi works and mod_python does not. > > Here’s the code which is the same in 2 files: myapp.wsgi; and myapp.py… > > def application(environ, start_response): > > status = '200 OK' > > output = '<html><body>\n' > > tbl = """<table border="5">""" > > for k,v in environ.items(): > > tbl += "\n<tr><td>%s</td><td>%s</td></tr>" % (k,v) > > tbl += "\n</table>" > > curpath = environ.get('PATH_INFO', '/') > > if curpath == '/maintenance/': > > output += '<h1>Maintenance page</h1>' > > else: > > output += """<h1>Hell!! Oh... Whirled!</h1> > > <a href="/myapp/maintenance/" target="_blank">Maintenance</a> <br />\n""" > > output += """%(tbl)s\n</body></html>""" % locals() > > response_headers = [('Content-type', 'text/html'), > > ('Content-Length', str(len(output)))] > > start_response(status, response_headers) > > return [output] > > > > The mod_wsgi implementation “routes” to the link properly but the mod_python > version does not. With other tests it seems like environ is not in sync when > using mod_python. I tried single process mode Apache and experienced the > same problem. > > > > For the mod_python handler I’ve tried the 2 known versions from: Nicholas > Borko; and Eli Collins. Both exhibit the same behavior. > > > > Is there some secret Apache directive needed to force mod_python to sync up? > Here’s how Apache is setup: > > <VirtualHost modwsgi:80> > > ServerName modwsgi > > ServerAlias modwsgi.local > > DocumentRoot /home/hydra/docroot/modwsgi > > WSGIScriptAlias /myapp /home/hydra/modwsgi/myapp.wsgi > > <Directory /home/hydra/docroot/modwsgi> > > Order allow,deny > > Allow from all > > </Directory> > > <Directory /home/hydra/modwsgi> > > Order allow,deny > > Allow from all > > </Directory> > > </VirtualHost> > > > > <VirtualHost modpython:80> > > ServerName modpython > > ServerAlias modpython.local > > DocumentRoot /home/hydra/docroot/modwsgi > > ScriptAlias /myapp /home/hydra/modwsgi/ > > <Directory /home/hydra/docroot/modwsgi> > > Order allow,deny > > Allow from all > > </Directory> > > <Directory /home/hydra/modwsgi> > > SetHandler python-program > > PythonHandler wsgi_handler > > PythonOption WSGI.Application myapp::application > > Order allow,deny > > Allow from all > > </Directory> > > </VirtualHost> > > > > Is this a handler problem or a mod_python implementation problem? Or a > problem with my understanding? > > > > What do you recommend? Not use mod_python. :-) SCRIPT_NAME/PATH_INFO is critical in WSGI applications for routing and mod_python can't provide that information accurately because of the way it hooks into Apache. As a result any WSGI adapter for mod_python would generally have a option to override what SCRIPT_NAME should be with PATH_INFO being recalculated appropriately. As to mod_wsgi, it hooks into Apache as a resource much like CGI does and so SCRIPT_NAME/PATH_INFO will behave as for CGI scripts and will thus be correct. Graham
|