views:

1295

answers:

1

I've noticed that whenever I enable the database settings on my django project (starting to notice a trend in my questions?) it gives me an internal server error. Setting the database settings to be blank makes the error go away. Here are the apache error logs that it outputs.

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.

And here is the django.wsgi file

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()

I have several other scripts that all connect to a mysql database just fine, if I run the tutorial server then it displays the admin panel correctly. I have tried changing the environ variables for eggs but still nothing changes.

+7  A: 

You need to set the PYTHON_EGG_CACHE environment variable. Apache/mod_wsgi is trying to extract the egg into a directory that Apache doesn't have write access to....or that doesn't exist.

It's explained in the Django docs here.

Does /Library/WebServer/.python-eggs exist? What does your Apache config file look like?

brianz