Hi guys I know this question has been asked many times but I've been searching through stackoverflow for hours and looking at similar issues but I haven't been able to figure out why I keep getting the authentication issue. Below is how I'm trying to connect to postgres via psycopg2
import psycopg2
psycopg2.connect("dbname=test0 user=doug host=localhost password=testpassword123 port=5432")
After running python3 test.py
I get the error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
psycopg2.connect("dbname=test0 user=doug host=localhost password=testpassword123 port=5432")
File "/home/doug/.local/lib/python3.8/site-packages/psycopg2/__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: password authentication failed for user "doug"
FATAL: password authentication failed for user "doug"
I've checked that the user doug
exists and has superuser privileges:
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
doug | Superuser | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
I've created the user doug with the following:
CREATE USER doug WITH PASSWORD 'testpassword123';
GRANT ALL PRIVILEGES ON DATABASE test0 to doug;
What am I doing wrong? Thank you. Also I've checked and confirmed that postgresql is running on port 5432.