A!die Software Studio Welcome to A!Die Software Studio

Django modpython hander BUG

by adie
2011-02-22 15:51:59
CentOS + Apache + mod_python + Django 增加 URL 重写后出现如下错误:
[Tue Feb 22 02:37:09 2011] [error] [client 222.211.193.246] PythonHandler django.core.handlers.modpython: Traceback (most recent call last):
[Tue Feb 22 02:37:09 2011] [error] [client 222.211.193.246] PythonHandler django.core.handlers.modpython:   File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch\n    result = object(req)
[Tue Feb 22 02:37:09 2011] [error] [client 222.211.193.246] PythonHandler django.core.handlers.modpython:   File "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py", line 228, in handler\n    return ModPythonHandler()(req)
[Tue Feb 22 02:37:09 2011] [error] [client 222.211.193.246] PythonHandler django.core.handlers.modpython:   File "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py", line 183, in __call__\n    os.environ.update(req.subprocess_env)
[Tue Feb 22 02:37:09 2011] [error] [client 222.211.193.246] PythonHandler django.core.handlers.modpython:   File "/usr/lib/python2.4/os.py", line 478, in update\n    self[k] = dict[k]
[Tue Feb 22 02:37:09 2011] [error] [client 222.211.193.246] PythonHandler django.core.handlers.modpython:   File "/usr/lib/python2.4/os.py", line 463, in __setitem__\n    putenv(key, item)
[Tue Feb 22 02:37:09 2011] [error] [client 222.211.193.246] PythonHandler django.core.handlers.modpython: TypeError: putenv() argument 2 must be string, not list

需要修改 /usr/lib/python2.4/site-packages/django/core/handlers/modpython.py 中

class ModPythonHandler(BaseHandler):
    request_class = ModPythonRequest

    def __call__(self, req):
        # mod_python fakes the environ, and thus doesn't process SetEnv.  This fixes that
        os.environ.update(req.subprocess_env)

修改为:

class ModPythonHandler(BaseHandler):
    request_class = ModPythonRequest

    def __call__(self, req):
        for envks, envval in req.subprocess_env.items():
            envvalscopy = req.subprocess_env[envks]
            if type(envvalscopy) == list:
                req.subprocess_env[envks] = envvalscopy[0]
        # mod_python fakes the environ, and thus doesn't process SetEnv.  This fixes that
        os.environ.update(req.subprocess_env)


▲评论

X 正在回复:
姓 名: 留下更多信息
性 别:
邮 件:
主 页:
Q Q:
来 自:
职 业:
评 论:
验 证:


Valid HTML 4.01 Strict Valid CSS!
Copyleft.A!die Software Studio.ADSS
Power by webmaster@adintr.com