Connection to server at "127.0.0.1", port 5432 failed: FATAL: password authentication failed for user "username"

I used this command to run postgresql container
docker run -it -e POSTGRES_USER=“username” -e POSTGRES_DB=“ny_taxi” -e POSTGRES_PASSWORD=“password” -v “${pwd}/ny_postgres_taxi_data:/var/lib/postgresql/data” -p 5432:5432 postgres:13

and then tried to connect through python using these commands
engine = create_engine(“postgresql://username:password@127.0.0.1:5432/ny_taxi”)
db = engine.connect()

I need some help as to why I am getting this error.

Please share the output of docker info and docker version + let us know if the python script runs in a container or on the same host as the docker engine.

Your post assumes that people on the forum use Python to connect to Postgres and they know what create_engine is. It could have been your cusom function. I was curious so I searched for it, but it is best if you provide an actualy tryable example.

I found this Engine Configuration — SQLAlchemy 2.0 Documentation

psycopg2 and sqlalchemy libraries were required, but it worked. I used Python 3.8 and your commands worked perfectly for me. The only difference is that I didn’t use a bind mount. Since the error message says “password authentication failed” the port worked so I think it is either that you used a wrong password or username for example because the quotation mark characters were not interpreted by the shell or it is because we used different python versions so I am interested in the answer to @meyay’s comment as well…