我在REDHAT 7中安装了postgres。然后我安装了python 3.6。我已经创建了虚拟环境。我还在 postgres 中创建了一个表。然后我执行了这个 python 脚本,出现了一些错误。
import psycopg2
conn = psycopg2.connect("dbname=postgres user=postgres host=localhost password=postgres")
Run Code Online (Sandbox Code Playgroud)
错误是:
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"
Run Code Online (Sandbox Code Playgroud)
猫 /var/lib/pgsql/12/data/pg_hba.conf
# TYPE DATABASE USER ADDRESS …Run Code Online (Sandbox Code Playgroud)