Colleagues, good. Trying to connect to the Postgress base in Python. The code gets into the database, and searches for a message by phone number. Here is the code

ith psycopg2.connect(dbname='', user='', password='', host='', port='', sslmode='') as conn: with conn.cursor() as cursor: cursor.execute("SELECT * FROM pfr WHERE xml_data LIKE '%+79169522420%'") record = cursor.fethall() for row in cursor: print(row) 

But the log

conn = _connect (dsn, connection_factory = connection_factory, ** kwasync) psycopg2.Operational Error: could not connect to server: Connection timed> out (0x0000274C / 10060) Is the server running on host "172.18.0.89" and accepting TCP / IP connections on port 5432?

  • Is there a firewall between you and the PostgreSQL server? Telnet tried to connect? - MaxU

1 answer 1

You need to configure pg_hba.conf .

After adding your host, run:

 /etc/init.d/postgresql restart 

If it does not help (and most likely does not help) - look towards the port from this mana .

  • I'm sitting on Windows, unfortunately - Sergey Bogdanov
  • Control Panel> System and Security> Windows Firewall> Allow an app through Windows Firewall - 0-Level UNIX Monk
  • one
    And for the future (this is by no means an attempt to say that you can’t ask questions), instead of writing what the code does in the database, you’d better specify the OS. It would be more relevant. - 0-Level UNIX Monk