python P8000 unable to connect: no pg_hba.conf entry for host

67 views Asked by At

I am using pg8000==1.30.5 in python 3.12

I was migrating from psycopg2

But connection I got an error:

pg8000.Connection(self.db_username, database=self.schema_name, host=self.db_host,
                               password=self.db_password,
                               port=self.db_port)

the error is the follow:

pg8000.exceptions.DatabaseError: {'S': 'FATAL', 'V': 'FATAL', 'C': '28000', 'M': 'no pg_hba.conf entry for host "xxx", user "xx", database "xx", no encryption', 'F': 'auth.c', 'L': '543', 'R': 'ClientAuthentication'}

You might think is postgres server problem, firewall, my vpn/ip, access control, permissions etc...

However I was working with "psycopg2" without any problem:

psycopg2.connect(database=self.schema_name, host=self.db_host, user=self.db_username,
                               password=self.db_password,
                               port=self.db_port)

I can not understand why one works and the other does not.

1

There are 1 answers

0
Tony Locke On

As of pg8000 1.31.0, by default an SSL connection will be attempted using lenient settings, so it should work in the same way as psycopg.