使用python脚本连接到postgresql数据库时无法使用.pgpass文件((( 我要连接的python脚本没有密码:
conn = psycopg2.connect("dbname='postgres' user='postgres' host='192.168.136.129'");
我的.pgpass:
^{pr2}$位于postgres用户的/var/lib/postgresql-主目录中。 但是,当我在本地连接到数据库时:
psql -U postgres
不询问密码。但对于python,会出现错误:
root@debian:/python_codes/Junior/Level1/DB1/Generator_py# python connect_db.py
Unable to connect to db...
Traceback (most recent call last):
File "connect_db.py", line 34, in connectdb
conn = psycopg2.connect("dbname='postgres' user='postgres' host='192.168.136.129'");
File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect
connection_factory=connection_factory, async=async)
OperationalError: fe_sendauth: no password supplied
根据此输出的提示:
您以Unix用户}
root
的身份运行命令,因此相应的.pgpass
文件必须位于根目录的HOME
目录中,这意味着不是/var/lib/postgresql
,而是/root
或{它的权限也必须限制为所有者可读,即
chmod 600 $HOME/.pgpass
相关问题 更多 >
编程相关推荐