3

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

当 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

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

任何想法?

4

2 回答 2

12
conn = psycopg2.connect("dbname=your_database user=postgres password=xxxx host=127.0.0.1 port=5432")
于 2013-07-27T22:20:17.580 回答
3

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

于 2017-04-26T11:34:06.800 回答