首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Django-postgresql: psycopg2 dsn密码错误

Django-postgresql: psycopg2 dsn密码错误
EN

Stack Overflow用户
提问于 2014-07-19 13:12:09
回答 1查看 568关注 0票数 0

我正在用postgresql DB运行python 2.7.3django 1.5.1。在设置了一个简单的django应用程序后,我得到了一个OperationalError at FATAL: password authentication failed for user "postgres"。当我检查本地变量时,我发现psycopg2连接接受了错误的密码。我已经在django settings.py文件中指定了正确的密码。此外,manage.py syncdb运行良好,这个问题出现了2/3次。

pg_hba.conf中的所有身份验证方法都设置为md5 and settings.py has HOSTlocalhost

EN

回答 1

Stack Overflow用户

发布于 2014-07-19 14:28:50

不要使用用户postgres来做这件事。

为你的应用程序创建一个用户和一个db,并仅使用该用户。

代码语言:javascript
复制
su
su postgres
createuser -P <dbusername>
:type and re-type <dbuserpasswd>
createdb -O <dbusername> <dbname>

检查你的pg_hba.conf

代码语言:javascript
复制
local   all    all    md5

重新启动postgresql服务器。

检查您的Django设置

代码语言:javascript
复制
DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
    'NAME': 'dbname',                      # Or path to database file if using sqlite3.
    # The following settings are not used with sqlite3:
    'USER': 'dbusername',
    'PASSWORD': 'dbuserpasswd',
    'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
    'PORT': '',                      # Set to empty string for default.
    }
}

重新启动您的http服务器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24836995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档