views:

1173

answers:

3

Hi Stackers,

I'm deploying my django site on a Ubuntu 8.10 server that I've set up from scratch. I'm totally new to this so there may be plenty of stuff that I've missed, but happily have found my way through to the point of deploying a website.

My last hurdle:

I'm getting an authentication error with postgresql

[Sun Apr 19 18:44:05 2009] [error] [client 124.254.102.127] 
 mod_wsgi (pid=30304): Exception occurred processing WSGI script '/home/acacian/webapps/acacian/deploy/acacian.wsgi'.
 Traceback (most recent call last):
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/handlers/wsgi.py", line 241, in __call__
     response = self.get_response(request)
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/core/handlers/base.py", line 73, in get_response
     response = middleware_method(request)
   File "/home/acacian/webapps/pinax-env/src/django-openid/django_openid/consumer.py", line 383, in process_request
     if self.session_key in request.session:
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/contrib/sessions/backends/base.py", line 43, in __contains__
     return key in self._session
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/contrib/sessions/backends/base.py", line 172, in _get_session
     self._session_cache = self.load()
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/contrib/sessions/backends/db.py", line 16, in load
     expire_date__gt=datetime.datetime.now()
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/manager.py", line 120, in get
     return self.get_query_set().get(*args, **kwargs)
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/query.py", line 269, in get
     num = len(clone)
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/query.py", line 68, in __len__
     self._result_cache = list(self.iterator())
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/query.py", line 207, in iterator
     for row in self.query.results_iter():
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/query.py", line 262, in results_iter
     for rows in self.execute_sql(MULTI):
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/models/sql/query.py", line 2288, in execute_sql
     cursor = self.connection.cursor()
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/backends/__init__.py", line 81, in cursor
     cursor = self._cursor()
   File "/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg/django/db/backends/postgresql_psycopg2/base.py", line 98, in _cursor
     self.connection = Database.connect(**conn_params)
 OperationalError: FATAL:  Ident authentication failed for user "acacian"

Note:

  • the same settings work fine under runserver and dbshell
  • mod_wsgi has been working with sqlite3 (i'm at the point of switching over)

acacian.wsgi (a little messy)

# basic_project.wsgi is configured to live in projects/basic_project/deploy.

import os
import sys
import site

sys.stdout = sys.stderr

from os.path import abspath, dirname, join
from site import addsitedir

# the project path & pinax src paths
sys.path.insert(0, abspath(join(dirname(__file__), "../../")))
sys.path.insert(0, abspath(join(dirname(__file__), "../../pinax-env/src/pinax")))
sys.path.insert(0, abspath(join(dirname(__file__), "../../pinax-env/src")))


sys.path = ['/home/acacian/webapps/acacian/apps', '/home/acacian/webapps/pinax-env/src/pinax/pinax/apps', '/home/acacian/webapps/acacian', '/home/acacian/webapps/pinax-env/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg', '/home/acacian/webapps/pinax-env/lib/python2.5/site-packages/pip-0.3.1-py2.5.egg', '/home/acacian/webapps/pinax-env/src/pinax', '/home/acacian/webapps/pinax-env/src/django-openid', '/home/acacian/webapps/pinax-env/src/atom-format', '/home/acacian/webapps/pinax-env/src/django-app-plugins', '/home/acacian/webapps/pinax-env/src/diff-match-patch', '/usr/lib/python2.5/site-packages/Django-1.0.2_final-py2.5.egg', '/usr/lib/python2.5/site-packages/pip-0.3.1-py2.5.egg', '/home/acacian/webapps/pinax-env/lib/python2.5', '/home/acacian/webapps/pinax-env/lib/python2.5/plat-linux2', '/home/acacian/webapps/pinax-env/lib/python2.5/lib-tk', '/home/acacian/webapps/pinax-env/lib/python2.5/lib-dynload', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/home/acacian/webapps/pinax-env/lib/python2.5/site-packages', '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages/PIL', '/var/lib/python-support/python2.5'] + sys.path


# A version of activate_this from the mod_wsgi documentation site.
ALLDIRS = ['/home/acacian/webapps/acacian/pinax-env/lib/python2.5/site-packages']

# Remember original sys.path.
prev_sys_path = list(sys.path) 

# Add each new site-packages directory.
for directory in ALLDIRS:
    site.addsitedir(directory)

# Reorder sys.path so new directories at the front.
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

#print sys.path

from django.conf import settings
os.environ["DJANGO_SETTINGS_MODULE"] = "acacian.settings"

sys.path.insert(0, join(settings.PINAX_ROOT, "apps"))
sys.path.insert(0, join(settings.PROJECT_ROOT, "apps"))

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

Thank you!

A: 

My guess is that your issue is in the database connection settings (settings.py). I am assuming you have already created the database and syncdb'd etc?

This article is awesome for setting up Django/Postgres/etc on Ubuntu 8.10 (I have followed it to set up a couple of VMs already): http://lethain.com/entry/2009/feb/13/the-django-and-ubuntu-intrepid-almanac/

Ricky
+5  A: 

The error:

Ident authentication failed for user "acacian"

means just that.

When you are using runserver or dbshell the Django process is running with your userid as process owner.

When you run Django under mod_wsgi, in daemon mode, it is running as the user specified in the WSGIDaemonProcess directive. If you are running mod_wsgi in embedded (non-daemon) mode then the userid will match the Apache process User directive.

So, what you need to do is add your user acacian as a user to postgresql using createuser just like you did with your own user name.

Van Gale
+1  A: 

You might find this blogpost helpful http://www.depesz.com/index.php/2007/10/04/ident/ - it tries to explain the "Ident authentication failed" error, it's source, and what can you do about it.

depesz