I am trying to connect my Cloud SQL PostgreSQL databse to my Compute Engine instance, via psycopg2. My connection string as follows:
con = psycopg2.connect(
dbname=config('DATABASE'),
user=config('USER'),
password=config('PASSWORD'),
host=config('HOST'),
port=config('PORT')
)
using port 5432 and the public IP address of the postgresql database. database, user, and password are all correct. When I run this code via the compute instance i get the following error
Traceback (most recent call last):
File "main.py", line 16, in <module>
bot.add_cog(Profile(bot))
File "/home/username/appname/Profile.py", line 22, in __init__
port=config('PORT')
File "/home/username/.local/lib/python3.7/site-
packages/psycopg2/__init__.py", line 126, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATAL: password authentication failed for user
"mygcloudusername"
FATAL: password authentication failed for user "mygcloudusername"
For some reason it seems to be trying to connect via my gcloud username as the user, even though the correct user is specified in the connection string. Where have I gone wrong here? How can i connect this correctly?