Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 915
Bhargav Avatar asked May 12 '17 04:05

Bhargav


2 Answers

The settings must be in uppercase - try changing it to 'PASSWORD'

like image 102
Todor Minakov Avatar answered Nov 14 '22 23:11

Todor Minakov


The key name 'password' should be in uppercase 'PASSWORD'. Also instead of defining password as global variable DATABASE_PASSWORD, you can use .bashrc file to save secure information and can fetch in settings.py like os.environ['DATABASE_PASSWORD']

like image 29
Maninder Singh Avatar answered Nov 14 '22 21:11

Maninder Singh