0
我们试图通过Python访问在104.154.90.232上运行的Odoo数据库。我用psycopg2来连接。通过Python进行Odoo-postgreSQL访问
我的代码是这样的:
import psycopg2
import sys
import pprint
conn_string = "host='104.154.90.232' dbname='dbname' user='user' password='password'"
print "connecting to the database\n ->%s"%(conn_string)
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
cursor.execute("SELECT * FROM hr_employee")
records = cursor.fetchall()
pprint.pprint(records)
的错误是:
Traceback (most recent call last):
File "test.py", line 6, in <module>
conn = psycopg2.connect(conn_string)
File "C:\Python27\lib\site-packages\psycopg2\__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection timed out (0x0000274C/10060)
是服务器上的主机 “104.154.90.232” 运行并在端口5432接受TCP/IP连接?
有人可以帮我建立连接吗?
并且服务器在那里运行并接受连接? –
检查服务器是否在端口5432上运行可能不是。 – Cherif
用于测试服务器是否正在运行通过此cmd ps ax | grep postgres'在您的终端 –