Postgresql error connecting from Python to Debian

-1

I am a newbie here, and am trying to connect to a Postgresql database in Debian 10 from Windows 10. Code is as below:

import psycopg2
try:
    dbConnection = psycopg2.connect(
    user = "", # user is here
    password = "", # password is here
    host = "192.168.56.30",
    port = "5432",
    database = "postgres")
    dbConnection.set_isolation_level(0) # AUTOCOMMIT
    dbCursor = dbConnection.cursor()
    dbCursor.execute("CREATE DATABASE weather")
    dbCursor.close()
    print("Job done!!")
except (Exception , psycopg2.Error) as dbError :
    print ("Error while connecting to PostgreSQL", dbError)
finally:
    print("")
#    if(dbConnection): dbConnection.close()

I am getting the below error : "Error while connecting to PostgreSQL could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "192.168.56.30" and accepting TCP/IP connections on port 5432?"

I have added listen_addresses = ’*’ to my postgresql.conf file.

I have added under IPV4 connections in my pg_hba.conf file I have added the below : host all all 192.168.56.1/32 md5

I have enabled and started the DB: sudo systemctl enable postgresql@11-main sudo systemctl start postgresql@11-main

What else could I be doing wrong here?

Here is the VirtualBox settings (as I am convinced the problem is the host connection), now I have messed around with them a bit trying to get it to work! Host connection

Host connection

Host connection 2

I have added listen address to the postgresql.conf file as below enter image description here

And an extract from the pg_hba.conf file is as below: A

As I am new to this, all help would be much appreciated.

postgresql
connection
debian
out
timed
asked on Stack Overflow Mar 5, 2020 by user3600952 • edited Mar 5, 2020 by user3600952

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0