django和mod_wsgi有数据库连接问题

时间:2009-05-13 20:13:16

标签: python django mod-wsgi

我注意到每当我在我的django项目上启用数据库设置(开始注意到我的问题中的趋势?)时,它就会给我一个内部服务器错误。将数据库设置设置为空白会使错误消失。以下是它输出的apache错误日志。

mod_wsgi (pid=770): Exception occurred processing WSGI script '/Users/teifionjordan/rob2/apache/django.wsgi'.
Traceback (most recent call last):
  File "/Library/Python/2.5/site-packages/django/core/handlers/wsgi.py", line 239, in __call__
    response = self.get_response(request)
  File "/Library/Python/2.5/site-packages/django/core/handlers/base.py", line 67, in get_response
    response = middleware_method(request)
  File "/Library/Python/2.5/site-packages/django/contrib/sessions/middleware.py", line 9, in process_request
    engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
  File "/Library/Python/2.5/site-packages/django/contrib/sessions/backends/db.py", line 2, in <module>
    from django.contrib.sessions.models import Session
  File "/Library/Python/2.5/site-packages/django/contrib/sessions/models.py", line 4, in <module>
    from django.db import models
  File "/Library/Python/2.5/site-packages/django/db/__init__.py", line 16, in <module>
    backend = __import__('%s%s.base' % (_import_path, settings.DATABASE_ENGINE), {}, {}, [''])
  File "/Library/Python/2.5/site-packages/django/db/backends/mysql/base.py", line 10, in <module>
    import MySQLdb as Database
  File "build/bdist.macosx-10.5-i386/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 4, in __bootstrap__
  File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 841, in resource_filename
    self, resource_name
  File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 1310, in get_resource_filename
    self._extract_resource(manager, self._eager_to_zip(name))
  File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 1332, in _extract_resource
    self.egg_name, self._parts(zip_path)
  File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 921, in get_cache_path
    self.extraction_error()
  File "/Library/Python/2.5/site-packages/setuptools-0.6c9-py2.5.egg/pkg_resources.py", line 887, in extraction_error
    raise err
ExtractionError: Can't extract file(s) to egg cache

The following error occurred while trying to extract file(s) to the Python egg
cache:

  [Errno 20] Not a directory: '/Library/WebServer/.python-eggs/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg-tmp'

The Python egg cache directory is currently set to:

  /Library/WebServer/.python-eggs

Perhaps your account does not have write access to this directory?  You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.

这是django.wsgi文件

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'rob2.settings'

sys.path.append('/Users/teifionjordan')

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

我有几个其他脚本都可以连接到mysql数据库,如果我运行教程服务器,那么它会正确显示管理面板。我曾尝试更改鸡蛋的环境变量,但仍然没有任何变化。

1 个答案:

答案 0 :(得分:8)

您需要设置PYTHON_EGG_CACHE环境变量。 Apache / mod_wsgi试图将egg提取到Apache没有写入权限的目录中......或者不存在。

Django docs here中解释了它。

/Library/WebServer/.python-eggs是否存在?您的Apache配置文件是什么样的?