【问题标题】:Password authentication fails when connecting to database through python psycopg2通过 python psycopg2 连接到数据库时密码验证失败
【发布时间】:2018-11-13 10:31:38
【问题描述】:

我正在尝试通过 python jupyter notebook 连接到我的本地 postgres 数据库。我正在使用似乎安装正确的 psycopg2。

我刚刚创建了一个名为“username”的用户,密码为“my_pw”。我是直接在 PG Admin 查询窗口中完成的:

CREATE USER username
GRANT ALL ON DATABASE my_db TO username;
ALTER USER username WITH PASSWORD 'my_pw';

我的连接代码如下所示:

import psycopg2 as p

conn = p.connect("host='localhost' dbname='my_db' user='username' password='my_pw'")

当我运行它时,我收到以下错误消息:

OperationalError: FATAL:  password authentication failed for user "username"

非常感谢您的帮助!

【问题讨论】:

    标签: python-3.x psycopg2 postgresql-10


    【解决方案1】:

    允许此用户进入 pg_hba.conf 配置文件。

    For more info

    【讨论】:

      【解决方案2】:

      像这样授予用户访问 pg_hba conf 上的 unix 套接字

      local   all             postgres                                md5
      local   all             <some user> # <- user registered here   md5
      

      如果你在/etc/postgresql/12/main/pg_hba.conf上使用Linux操作系统编辑文件

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-06-26
        • 1970-01-01
        • 2021-09-05
        • 2018-02-07
        • 2017-09-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多