psycopg2无法看到我的PostgreSQL实例

时间:2013-07-27 22:17:33

标签: postgresql psycopg2

我在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

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

有什么想法吗?

2 个答案:

答案 0 :(得分:11)

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

答案 1 :(得分:1)

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