Opened 12 years ago

Closed 9 years ago

#3126 closed defect (duplicate)

modpython handler behaves differently when url matches existing file

Reported by: Arthur Hebert Owned by: Adrian Holovaty
Component: Core (Other) Version: master
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I am migrating my site from PHP to Django, so my public_html directory is full of my old files, such as index.php. Such files are no longer loaded by apache, because they are overridden by /etc/apache2/modules.d/16_mod_python.conf:

<Directory /space/arthur/public_html/>
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE artybear.settings
    PythonPath "['/home/arthur/projects'] + sys.path"
    PythonDebug On

If I request a url that points to the name of a file that exists under the public_html/ directory (not including the file's extension), then I get the following error:

Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/lib/python2.4/site-packages/mod_python/", line 299, in HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.4/site-packages/django/core/handlers/", line 177, in handler
    return ModPythonHandler()(req)

  File "/usr/lib/python2.4/site-packages/django/core/handlers/", line 137, in __call__

  File "/usr/lib/python2.4/", line 478, in update
    self[k] = dict[k]

  File "/usr/lib/python2.4/", line 463, in __setitem__
    putenv(key, item)

TypeError: putenv() argument 2 must be string, not list

For example, will return the Django debug page, but will give the error above. If I remove the file index.php from the public_html/ directory, then will return the Django debug page.

Oddly, will return the Django debug page. The problem only seems to occur when the url points to the basename of a file that Apache would otherwise handle with another program. Some further tests:

$ cd /space/arthur/public_html/
$ touch foobar.php            # returns error page
$ mv foobar.php foobar        # returns Django debug page
$ mv foobar foobar.txt        # returns error page
$ mv foobar.txt    # returns Django debug page

This is problematic if there's a file called admin.php, because it returns the error page instead of the mapped url (Django's admin page).

I have Django source revision 4193, according to svn update.

Change History (5)

comment:1 Changed 12 years ago by James Bennett

This sounds like an Apache configuration issue; the input coming from apache itself is bad, and is causing Django to error out.

Make sure that there are no directives in your httpd.conf telling Apache to use other handlers (like mod_php) for file types which exist in that directory; IIRC, Apache calls all listed handlers, in order, while processing a request, not just the first or last one found.

comment:2 Changed 12 years ago by Arthur Hebert

You are right. I am unable to fix this on the mentioned system, but I just got to try out a newly installed server, and it does not produce the error.

comment:3 Changed 12 years ago by Chris Beaven

Resolution: worksforme
Status: newclosed

If it's working on a newly installed server, then let's put it down to a misconfiguration. If anyone else has this problem, please re-open.

comment:5 Changed 9 years ago by whoisthenirk

Resolution: worksforme
Status: closedreopened

New to Django and having a very similar problem. The exact same error message comes up only when i access a .py file without the ".py" in the URL. Likewise when any other URL is entered, I get the Django error page instead.

My httpd.conf:

<location "/miniFBpy">

    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    PythonPath "['/home/nick/django_projects'] + sys.path"
    SetEnv DJANGO_SETTINGS_MODULE miniFBpy.settings
    PythonOption django.root /miniFBpy

    PythonDebug On

My apache2 default file:

	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
		AddHandler mod_python .py
		PythonHandler mod_python.publisher
		PythonDebug On

However, if I forsake the "PythonHandler django.core.handlers.modpython" and simply maintain the PythonHandler as mod_python.publisher, the .py page becomes accessible -- but naturally the Django error pages disappear. However, forsaking the "PythonHandler mod_python.publisher" and maintaining the django.core.handlers.modpython as the PythonHandler makes no difference, and the same error results.

comment:6 Changed 9 years ago by Karen Tracey

Resolution: duplicate
Status: reopenedclosed

#9327 describes a different situation that leads to the same traceback. Closing this in favor of that because that one has a clear understanding of what Apache/mod_python behavior leads to the problem.

Note: See TracTickets for help on using tickets.
Back to Top