python - 如何在 potgresql 中启动 GSSAPI
问题描述
我在REDHAT 7中安装了postgres。然后我安装了python 3.6。我已经创建了虚拟环境。我还在 postgres 中创建了一个表。然后我执行了这个 python 脚本,我得到了一些错误。
import psycopg2
conn = psycopg2.connect("dbname=postgres user=postgres host=localhost password=postgres")
错误是:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/scripts/san-automation/lib/python3.7/site-packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not initiate GSSAPI security context: Unspecified GSS failure. Minor code may provide more information
could not initiate GSSAPI security context: Server not found in Kerberos database
FATAL: Ident authentication failed for user "postgres"
猫 /var/lib/pgsql/12/data/pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 ident
host replication all ::1/128 ident
解决方案
看起来它正在抢先加载您的 gss/kerberos 配置文件(即使它不会使用它们),并在其中找到它不喜欢的东西。但这似乎只是一个警告。真正的错误是最后一行:
致命:用户“postgres”的身份验证失败
我认为这与 GSS 没有任何关系。查看服务器的日志文件以了解 ident 失败的原因。
如果您显示的 pg_hba.conf 是有效的,那么在您的系统上,localhost 必须解析为 ::1,而不是 127.0.0.1。也就是说,它使用的是 ipv6 而不是 ipv4。
推荐阅读
- jquery - 移动手风琴的标签?
- javascript - 为什么将文本元素作为元素插入到父 div 的子节点之间?
- android - 反应原生 firebase 与 expo 裸应用程序的集成
- django - username = request.data.get('username', '0') 中的参数是什么
- java - 如何在Java方法中返回一个数组
- amazon-web-services - TLS 握手表示 AWS IoT 控制台创建的证书无效
- django - VueX 动作没有映射。消息 - [TypeError:无法读取未定义的属性“调度”]
- c# - WIX 以管理员权限执行自定义操作
- crystal-reports-2010 - 使用 Crystal Reports XI 需要删除部分字符串
- amazon-web-services - AWS VPC - 与其他虚拟网络的逻辑隔离