[Python] running postgres DB in docker but its not connecting to my username and password env...

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    I'm am unable to figure this out, i'm trying to connect to the postgres instance running on docker. within the environment variables i selected

    postgres:
    image: postgres:latest
    container_name: postgres
    ports:
    - "5432:5432"
    environment:
    POSTGRES_USER: postgres
    POSTGRES_PASSWORD: postgres
    POSTGRES_DB: voting
    healthcheck:
    test: [ "CMD", "pg_isready", "-U", "postgres" ]
    interval: 10s
    timeout: 5s
    retries: 5


    My understanding of this. is where i select the superuser that postgres runs on, which should be postgres for both username and password.

    Now when i do try and connect using sqlalchemy

    engine = create_tables_for_voting.create_tables("postgresql+psycopg2://postgres:postgres@localhost:5432/voting")

    Session = sessionmaker(bind=engine)
    session = Session()


    This should ideally work but the error messages i'm getting on the terminal side is

    There was an error when connection to db: (psycopg2.OperationalError) connection to server at "localhost" :):1), port 5432 failed: FATAL: password authentication failed for user "username"

    Now when i do query through docker there is no user called username

    enter image description here

    Really stumped here and i think its something simple i must be overlooking

    I've tried changing the user and have also tried checking the different users available and nothing worked

    No other users implemented

    Continue reading...

Compartilhe esta Página