Django fe_sendauth: no password supplied error, unable to connect to postgres database

Viewed 10613

I am trying to provision a server with a django applciation with postgresql as its backend. After installing the required packages, database and environment when I try to run migrations, I get the following error

Traceback (most recent call last):
  File "/var/envs/traveldbapi/lib/python3.4/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
    self.connect()
  File "/var/envs/traveldbapi/lib/python3.4/site-packages/django/db/backends/base/base.py", line 189, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/var/envs/traveldbapi/lib/python3.4/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/var/envs/traveldbapi/lib/python3.4/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: fe_sendauth: no password supplied


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/var/envs/traveldbapi/lib/python3.4/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
 ====
 ommitting some lines
 ====
    connection = Database.connect(**conn_params)
  File "/var/envs/traveldbapi/lib/python3.4/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: fe_sendauth: no password supplied

I confirmed that the relevant DATABASE setting required for django are present:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'HOST': 'localhost',
        'NAME': DATABASE_NAME,
        'USER': DATABASE_USER,
        'password': DATABASE_PASSWORD
    }
}

I am not sure why this error is happening because this is the same setup I use on my local machine and it works. To confirm that there aren't any issues with my pg_hba.conf I started from a fresh installation. The config hasn't been modified in any way and the application user has the required privileges on the application database.

5 Answers

make your HOST variable empty as

'HOST': '',

OperationalError: fe_sendauth: no password supplied

you should change password to uppercase 'PASSWORD'

In using Django,ensure you have a .env file and configure properly your .postgres and .django envs esp provide Database URL in your .postres or in .env file as such:

DATABASE_URL=psql://postgres:yourpassword@127.0.0.1:5432/databasename
POSTGRES_HOST=*
POSTGRES_PORT=5432
POSTGRES_DB=tutor
POSTGRES_USER=postgres
POSTGRES_PASSWORD=yourpassword
DJANGO_ALLOWED_HOSTS=['.herokuapp.com', 'localhost', '127.0.0.1', '[::1]', '0.0.0.0']
# DJANGO_DEBUG=False # disable debugging on production
DJANGO_DEBUG=False # disable debugging if hosts list is not empty

For more info on environmental variables please refer to: # .env using django-environ

Related