Odoo-postgreSQL access through Python

0

We are trying to access the database of Odoo running on 104.154.90.232 through Python. I have used psycopg2 to connect.

My code is like this:

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)

The error is:

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)

Is the server running on host "104.154.90.232" and accepting TCP/IP connections on port 5432?

Can someone help me establish the connection?

python
postgresql
openerp
asked on Stack Overflow Jun 29, 2017 by Antriksh Mathur • edited Jun 29, 2017 by Thierry Lathuille

1 Answer

0

As far as i know, the default pg_hba.conf file only allows connections resp. authentification from the local system. You have to define new rules for external access. It's described in the file, how to do that.

Then ofcourse there has to be a correctly configured database user for odoo.

answered on Stack Overflow Jun 29, 2017 by CZoellner

User contributions licensed under CC BY-SA 3.0