There can be Ident authentication errors in PostgreSQL while connecting with psycopg2 module, hese errors can be resolved with below steps.
navigate to "pg_hba.conf".
edit pg_hba.conf with entires show in updated entries below(path may be different according to pgsql
version)
sudo vi /var/lib/pgsql/12/data/pg_hba.conf
Initial entry(this was the default setting, change this to as shown in updated entry):