psycopg2 看不到我的 PostgreSQL 实例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17903006/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:02:41  来源:igfitidea点击:

psycopg2 can't see my PostgreSQL instance

postgresqlpsycopg2

提问by Benjamin Toueg

I'm on Windows, with a 32bit install of python 2.6.6 and psycopg2.

我在 Windows 上,安装了 32 位的 python 2.6.6 和 psycopg2。

When psycopg2 tries to connect, it gets an OperationalError:

当 psycopg2 尝试连接时,它会得到一个OperationalError

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>> conn = psycopg2.connect("dbname=your_database user=postgres password=xxxx host=127.0.0.1:5432")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python26\lib\site-packages\psycopg2\__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: could not translate host name "127.0.0.1:5432" to address: Unknown server error

I am able to connect to PostgreSQL instance with pgAdmin3 on 127.0.0.1:5432.

我可以使用 pgAdmin3 on 连接到 PostgreSQL 实例127.0.0.1:5432

Any idea?

任何的想法?

回答by Anthony Perot

conn = psycopg2.connect("dbname=your_database user=postgres password=xxxx host=127.0.0.1 port=5432")

回答by Yankee

Removing the port :5432from the hostname worked for me.

:5432host名称中删除端口对我有用。