Joff
Joff

Reputation: 12177

postgresql django not sending password

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.

Upvotes: 4

Views: 8282

Answers (2)

Umar Hayat
Umar Hayat

Reputation: 4991

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")
    }
}

Upvotes: 4

munsu
munsu

Reputation: 2062

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.

Upvotes: 4

Related Questions