psycopg2可以';我看不到我的PostgreSQL实例

psycopg2可以';我看不到我的PostgreSQL实例,postgresql,psycopg2,Postgresql,Psycopg2,我在Windows上,安装了32位的python 2.6.6和psycopg2 当psycopg2尝试连接时,它会收到一个操作错误: 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 psycop

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

当psycopg2尝试连接时,它会收到一个
操作错误

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
win32上的Python 2.6.6(r266:84297,2010年8月24日,18:46:32)[MSC v.1500 32位(英特尔)] 有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。 >>>导入psycopg2 >>>conn=psycopg2.connect(“dbname=your_database user=postgres password=xxxx主机=127.0.0.1:5432”) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 文件“C:\Python26\lib\site packages\psycopg2\\uuuu init\uuuuu.py”,第164行,在connect中 连接=连接(dsn,连接工厂=连接工厂,异步=异步) psycopg2.OperationalError:无法将主机名“127.0.0.1:5432”转换为地址:未知服务器错误 我能够在
127.0.0.1:5432
上使用pgAdmin3连接到PostgreSQL实例


有什么想法吗?

主机上删除端口
:5432
对我来说很有效。

我认为最好使用
psycopg2.connect(数据库='your_database',用户='postgres',密码='xxxx')
命名参数更好(可读性更强)连接字符串、localhost和5432是默认值,所以您根本不需要传递它们。
conn = psycopg2.connect("dbname=your_database user=postgres password=xxxx host=127.0.0.1 port=5432")