Skip to Content
Menu
This question has been flagged
2 Replies
11666 Views

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 in establishing the connection?

Avatar
Discard
Author Best Answer

Tried this but doesn't help. 

Avatar
Discard
Best Answer

Try to check your server accept remote connections in the ip/ports you're using to establish the connection.

https://www.postgresql.org/docs/9.1/static/auth-pg-hba-conf.html


If you want to retrieve the records from a specific model maybe the XMLRPC API can be more efficient, because you can call methods from the ORM API directly, in your case, you can use the search_read() method to get the information you need . 

https://www.odoo.com/documentation/10.0/api_integration.html 



Avatar
Discard