Reputation: 79
I'm trying to connect my flask application to an rds instance on aws (psql server), this is being done using a local port. i ssh from my terminal to the server on port 1234 and connect any application to the port so the connection would be localhost:1234. this works perfectly fine when i connect from a separate python file, but when i try to connect from my flask application it fails, and gives me the following
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (::1), port 1234 failed: FATAL: password authentication failed for user "postgres"
connection to server at "localhost" (::1), port 1234 failed: FATAL: password authentication failed for user "postgres"
I'm guessing the issue is probably due to having my flask application running on localhost and trying to connect to local host, but they're on different ports so I'm not sure why that would be an issue. here's the code I'm using
from sqlalchemy import create_engine, text
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine, MetaData
Base = automap_base()
engine = create_engine('postgresql+psycopg2://postgres:<pass>\
@localhost:1234/<servername>')
metadata = MetaData()
metadata.reflect(engine)
Base = automap_base(metadata=metadata)
Base.prepare()
session = Session(engine)
as i mentioned, this works perfectly fine when i run it from a separate python script, but it fails on the flask application. any insight is greatly appreciated
Upvotes: 0
Views: 318
Reputation: 79
the problem was the connection string, for some reason inside the flask app it was getting misinterpreted
the following connection string solved the issue
engine = create_engine(r'postgresql+psycopg2://postgres:<pass>@localhost:1234/<name>')
Upvotes: 1