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'在您的終端 –