Apache-Django WSGI异常:ValueError:格式为零长度字段名称

时间:2012-06-29 07:46:40

标签: django apache mod-wsgi

我在Debian系统上用apache2 + mod_wsgi建立一个django服务器(1.4,python 2.7)。从django方面来说,一切都很完美,如果我运行manage.py runserver,开发服务器会正​​确显示网站,但是,当我尝试设置我的apache服务器来运行WSGI时,它无法显示ValueError。

这是 mysite.wsgi

ALLDIRS = ['/usr/local/lib/python2.7/site-packages']
# the above directory depends on the location of your python installation.
# if using virtualenv, it will need to match your projects locale.
import os
import sys
import site

os.environ['DJANGO_SETTINGS_MODULE'] = 'ggDatabase.settings'
prev_sys_path = list(sys.path)
sys.path.append("/usr/local/lib/python2.7")
path = "/home/acad/statsdb/src"
if path not in sys.path:
        sys.path.append(path)
        sys.path.append("/home/acad/statsdb/src/ggDatabase")
for directory in ALLDIRS:
        site.addsitedir(directory)
        new_sys_path = []
        for item in list(sys.path):
            if item not in prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
                sys.path[:0] = new_sys_path

# change this depending on your project.

site.addsitedir("/home/acad/statsdb/src/ggDatabase/")


os.environ['PYTHON_EGG_CACHE'] = '/home/acad/.python-eggs'
os.environ['SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

这是 apache VirtualHost配置

<VirtualHost 127.0.0.1:8000>
    ServerName mysite.com
    ServerAlias www.mysite.com
    <Directory /home/acad/statsdb/src/ggDatabase>
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn
    CustomLog /var/log/apache2/mysite.com.access.log combined
    ErrorLog /var/log/apache2/mysite.com.error.log

    WSGIDaemonProcess mysite.com user=acad group=acad threads=25 python-path=/usr/local/lib/python2.7
    WSGIProcessGroup mysite.com
    WSGIScriptAlias / /home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi

</VirtualHost>

这是我在测试服务器上的确切配置,它在那里工作,但新服务器在尝试运行wsgi脚本时遇到问题:

[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] mod_wsgi (pid=26233): Target WSGI script '/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi' cannot be loaded as Python module.
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] mod_wsgi (pid=26233): Exception occurred processing WSGI script '/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi'.
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] Traceback (most recent call last):
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]   File "/home/acad/statsdb/src/ggDatabase/apache/mysite.wsgi", line 31, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]     import django.core.handlers.wsgi
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 8, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]     from django import http
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/site-packages/django/http/__init__.py", line 11, in <module>
[Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]     from urllib import urlencode, quote
 [Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]   File "/usr/local/lib/python2.7/urllib.py", line 1228, in <module>
 [Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1]     _safe_map[c] = c if (i < 128 and c in always_safe) else '%{:02X}'.format(i)
 [Fri Jun 29 09:38:14 2012] [error] [client 127.0.0.1] ValueError: zero length field name in format

错误是如此通用,以至于我真的不知道会出现什么问题。有什么想法吗?

提前致谢!

布鲁诺

1 个答案:

答案 0 :(得分:0)

解决了它。如果有人有类似的错误,请确保打印sys.version,你可能会发现(正如我所做的)wsgi是在另一个已安装的python版本下配置的。

如果是这种情况,请使用--with-python选项重新安装mod_wsgi。