小编rah*_*gal的帖子

Psycopg2 操作错误:无法连接到服务器:没有这样的文件或目录

尝试在 python shell 中连接到 postgresql 但遇到了一些问题。

我正在使用适用于 Linux 的 Windows 子系统。我尝试将端口更改为 5433 而不是 5432。并尝试设置 host="/tmp/"。这些都不起作用。

我尝试运行这个。

>>> import psycopg2
>>> conn = psycopg2.connect(dbname="postgres", user="postgres")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/anaconda3/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Run Code Online (Sandbox Code Playgroud)

数据库“postgres”出现在数据库列表中:

                              List of databases
   Name    |  Owner   | Encoding | …
Run Code Online (Sandbox Code Playgroud)

python postgresql shell psycopg2

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

postgresql ×1

psycopg2 ×1

python ×1

shell ×1