[Python] Psycopg2 to PostgresSQL Docker - UTF8 Connection error

Discussão em 'Python' iniciado por Stack, Março 26, 2025.

  1. Stack

    Stack Membro Participativo

    Hello i have been working on a personnal project, and i have been using docker and Psycopg2 for the first time. I deployed a PostGreSQL Server on docker, i'm trying to connect to it using a python script (With the objectiv to use some Airflow DAGs in the future) Issue i get is always the same error whatever i do when trying to connect to the database.

    Python Code is very simple :

    import psycopg2

    conn = psycopg2.connect(
    dbname="testdb", user="user", password="pass", host="localhost", port=5432
    )

    conn.close()


    Always get the same issue :

    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 103: invalid continuation byte


    Checked every parameters, for non utf-8 caracthers but havent found anything also looked everywhere but not any solution is fixing this error message.

    Postgres is in UTF8 as expected Edit : I run this on windows

    Continue reading...

Compartilhe esta Página