1
我在Windows上,使用32位安装的python 2.6.6和psycopg2。psycopg2看不到我的PostgreSQL实例
当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
。
有什么想法?
直截了当,谢谢! –
有一个冷却时间,我不能太快接受答案;) –
我认为使用'psycopg2.connect(database ='your_database',user ='postgres',password ='xxxx')'命名参数比连接字符串更好(更易读),localhost和5432是默认值,所以你根本不需要传递它们。 – omikron