I have a python/django application, 'mysite', which connects to bdbxml. The application works fine using the django development server but fails when run using mod_wsgi with apache - my chosen route for production. Specifically it is the parts of the application that connect to the database that fail with a very unhelpful message, 'finally' pops bad exception.
I believe from googling that this error is a generic error that is generated by C++ applications when there is no other error message to generate, but I am not a C++ expert so don't really know what it means.
My views.py function looks like:
def dbquery(request):
mgr = XmlManager()
container = mgr.openContainer("/wsgi/mysite/mysite.bdbxml")
results = container.getAllDocuments(0)
for value in results:
document = value.asDocument()
return HttpResponse (document.getName())
my django.wsgi file (using the suggested format from Graham Dumpleton) looks like:
import os, sys
sys.path.append('/wsgi')
sys.path.append('/wsgi/mysite')
import settings
import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')
command.validate()
import django.conf
import django.utils
django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
and httpd.conf looks like:
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias / /wsgi/mysite/apache/django.wsgi
<Directory /wsgi/mysite>
Order deny,allow
Allow from all
</Directory>
Does anyone know how to solve this problem?
thanks
Update
Following suggestion by Graham Dumpleton below that the problem may be linked to permissions on the database, here is the output of ls -las showing permissions on the directory where the database is located. All files and folders are owned by apache.
4 drwxr-xr-x 5 apache apache 4096 May 5 06:26 .
4 drwxr-xr-x 3 apache apache 4096 May 4 22:09 ..
4 drwxr-xr-x 2 apache apache 4096 May 5 14:52 apache
4 -rw-r--r-- 1 apache apache 16 May 5 05:05 index.html
4 -rw-r--r-- 1 apache apache 12 May 5 04:52 index.html~
0 -rw-rw-r-- 1 apache apache 0 May 4 22:09 __init__.py
4 -rw-r--r-- 1 apache apache 114 May 5 05:39 __init__.pyc
4 -rw-rw-r-- 1 apache apache 503 May 4 22:09 manage.py
164 -rwxr-xr-x 1 apache apache 163840 May 5 05:23 mysite.bdbxml
4 drwxr-xr-x 2 apache apache 4096 May 5 05:26 scripts
8 -rw-rw-r-- 1 apache apache 5060 May 5 04:50 settings.py
8 -rw-rw-r-- 1 apache apache 5031 May 4 22:09 settings.py~
4 -rw-r--r-- 1 apache apache 2784 May 5 05:39 settings.pyc
4 drwxr-xr-x 2 apache apache 4096 May 5 04:49 templates
4 -rw-rw-r-- 1 apache apache 639 May 5 05:32 urls.py
4 -rw-rw-r-- 1 apache apache 600 May 5 04:42 urls.py~
4 -rw-r--r-- 1 apache apache 444 May 5 05:40 urls.pyc
4 -rw-r--r-- 1 apache apache 609 May 5 06:26 views.py
4 -rw-r--r-- 1 apache apache 609 May 5 06:26 views.py~
4 -rw-r--r-- 1 apache apache 914 May 5 06:26 views.pyc
Having gone through a complete re-install I can now confirm that Graham's comments were spot on and correct. The issue was related to permissions.
Once the apache process was made the owner of the directory containing the application and the database files it all started working.
Thanks!