Peicopg2 authentication for user authentication

It seems I installed PostgreSQL 9.5.5 correctly. and Psycopg2 on Ubuntu 16.04, and you can log in via:

sudo -u postgres psql

If I issue \conninfo, I get the following:

You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".

Of course, I would have to connect via psycopg2 in the same way as shown here , but the script:

#!/usr/bin/python
import psycopg2
conn = psycopg2.connect("dbname=postgres user=postgres") 
conn.close()

gives me:

psycopg2.OperationalError: FATAL:  Peer authentication failed for user "postgres"

I only need PostgreSQL for personal use, so I do not want to enable TCP authentication.

How to use peer-to-peer authentication with the "postgress" user in Psycopg2?

+4
source share
3 answers

Postgres Linux, script.

Python script sudo -u postgres.

+4

conn = psycopg2.connect("dbname='template1' user='dbuser' host='localhost' password='dbpass'")
+4

This is what the yoru call looks like.

!/usr/bin/python
import psycopg2
conn = psycopg2.connect(database="postgres", user="postgres", password="postgres", port=5432)

conn.close()
0
source

Source: https://habr.com/ru/post/1660444/


All Articles