2

I am getting the error OperationalError: fe_sendauth: no password supplied on my production server but I cannot see why...

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'dbname',
        'USER': 'dbuser',
        'PASSWORD': PROD_DB_PASSWORD,
        'HOST': 'localhost',
        'PORT': '5432',
        }
    }

pg_hba.conf:

host    dbname       dbuser       localhost               md5

If I do psql -d dbname -U dbuser -h localhost and then enter the password at the prompt I can see that it works so IDK why django is not sending the password and IDK where to look from here.

Joff
  • 11,247
  • 16
  • 60
  • 103
  • Possible duplicate of [fe\_sendauth: no password supplied](http://stackoverflow.com/questions/17996957/fe-sendauth-no-password-supplied) – e4c5 Dec 16 '16 at 01:33
  • @e4c5 it is not a duplicate...His solution was to just use 'trust' which is specifically what I am trying to move away from – Joff Dec 16 '16 at 01:57
  • the key point in that question was the reload – e4c5 Dec 16 '16 at 01:58

2 Answers2

3

I suspect you're not passing the password correctly. Here's how you debug. After the DATABASES line in settings.py, can you try printing out the dict.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'dbname',
        'USER': 'dbuser',
        'PASSWORD': PROD_DB_PASSWORD,
        'HOST': 'localhost',
        'PORT': '5432',
        }
    }
print DATABASES

Then manage.py runserver as you would.

See if the password is properly passed. Apologies my rep's not enough to comment yet.

munsu
  • 1,914
  • 19
  • 24
  • I tried it in a shell...Had a problem with an old config importing the wrong set of settings on the production server – Joff Dec 16 '16 at 04:23
  • I printed the DATABASES and USER and PASSWORD is there properly. yet I get `FATAL: password authentication failed for user "db_admin"` – Shanika Ediriweera Mar 22 '20 at 07:36
  • will need more info than that @ShanikaEdiriweera. Try filing a new question. – munsu Mar 23 '20 at 12:36
1

For future readers also check the spelling and later cases. All database keys must be in UPPER CASE e.g ENGINE, NAME, USER, PASSWORD, HOST and PORT.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': os.getenv("DB_NAME", "db_name"),
        "USER": os.getenv("DB_USERNAME", "db_user"),
        "PASSWORD": os.getenv("DB_PASSWORD", "db@password"),
        "HOST": os.getenv("DB_HOST", "localhost"),
        "PORT": os.getenv("DB_PORT", "5432")
    }
}
Umar Hayat
  • 4,300
  • 1
  • 12
  • 27