Django fe_sendauth:没有提供密码错误,无法连接到postgres数据库

时间:2017-05-12 04:56:53

标签: python django postgresql

我正在尝试使用postgresql作为后端来配置带有django applciation的服务器。在我尝试运行迁移时安装所需的包,数据库和环境后,出现以下错误

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

我确认django所需的相关DATABASE设置存在:

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

我不确定为什么会发生这种错误,因为这与我在本地计算机上使用的设置相同而且可以正常工作。要确认我的pg_hba.conf没有任何问题,我是从全新安装开始的。配置没有以任何方式进行修改,应用程序用户在应用程序数据库上具有所需的权限。

4 个答案:

答案 0 :(得分:2)

密钥名称&#39;密码&#39; 应为大写&#39; PASSWORD&#39; 。另外,不是将密码定义为全局变量DATABASE_PASSWORD,而是可以使用.bashrc文件来保存安全信息,并且可以在 settings.py 中获取os.environ['DATABASE_PASSWORD']

答案 1 :(得分:0)

将您的HOST变量设置为空

'HOST': '',

答案 2 :(得分:0)

OperationalError:fe_sendauth:未提供 密码

您应该将密码更改为大写 'PASSWORD'

答案 3 :(得分:0)

在使用Django时,请确保您具有.env文件,并正确配置.postgres和.django envs esp,例如,在.postres或.env文件中提供数据库URL:

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

有关环境变量的更多信息,请参阅:#.env using django-environ