2025, Oct 07 13:00

Troubleshooting Odoo 18 on Windows: psycopg2 UnicodeDecodeError caused by non-UTF-8 PostgreSQL DSN (byte 0xe7, ç)

Fix Odoo 18 on Windows crashes: psycopg2 UnicodeDecodeError (byte 0xe7) from non-UTF-8 PostgreSQL DSN values in config, env vars, pg_service.conf. Learn how.

Odoo 18 on Windows may start cleanly, load addons, and then crash right after spinning up the HTTP service with a UnicodeDecodeError coming from psycopg2. The error typically looks like a UTF-8 decoding failure on byte 0xe7, which corresponds to the character ç. In practice, this points to a non‑UTF‑8 character sneaking into the database connection information used to reach PostgreSQL.

Repro in context

On a fresh clone with a virtual environment and dependencies installed, the server is launched like this:

PS D:\tarefas\trarefa_kaue_1\teste\odoo> python odoo-bin -r odoo -w 123

Logs confirm the server starts, but then a background thread throws:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe7 in position 78: invalid continuation byte

What’s really happening

The failure originates inside psycopg2.connect, while it assembles or parses the DSN (connection string) to PostgreSQL. The presence of 0xe7 means the character ç (c cedille) is present in the connection path somewhere and is not being interpreted as UTF‑8. That character can live in many places: in a database name, user name, host name, or even a Windows path segment used by the stack to discover config. When any of these values contain ç (or a similar non‑ASCII character), psycopg2’s decoding step can explode during the first cron thread or any database access.

That 0xe7 is the ç character. Somewhere in your database DSN (connection string, database name...) or Windows environment variable there’s a non‑UTF‑8 character (probably ç in a folder, user, or host name...).

Where the DSN comes from on Windows

Odoo passes connection parameters to psycopg2. Those parameters are sourced from several places in a well‑defined order. First are the odoo-bin arguments. You can provide the database name, user, password, host, and port directly on the command line, along with paths to addons and config. For reference, typical switches include:

-d <databasename> --database <databasename>
-r <user>        --db_user <user>
-w <password>    --db_password <password>
--db_host <hostname>
--db_port <port>
-c <config>      --config <config>
-D <data-dir-path> --data-dir <data-dir-path>

If not fully specified on the command line, Odoo then reads the configuration file to fill in the same parameters. A minimal example looks like:

db_host = localhost
db_port = 5432
db_user = odoo
db_password = 123

If anything is still missing, psycopg2 honors standard PostgreSQL environment variables. The ones that matter are PGHOST, PGPORT, PGUSER, PGPASSWORD, and PGDATABASE. Finally, on Windows there is also a PostgreSQL service file that can inject settings: %APPDATA%\postgresql\pg_service.conf. Any of these sources can carry a non‑UTF‑8 character into the DSN.

How to fix it

The most likely cause in this scenario is a non‑UTF‑8 character, specifically ç, present in one of the DSN inputs. Eliminate that character wherever it appears in the connection path. Inspect the odoo-bin arguments, the Odoo configuration file, the PG* environment variables, and the Windows PostgreSQL service file. Also consider any folder, user, or host name that may be implicitly referenced and contains ç. Make sure the actual values used for host, database, user, and password are plain ASCII or valid UTF‑8.

As a sanity check, make sure the Odoo configuration content that feeds the connection is free from special characters. A clean baseline looks like this:

db_host = localhost
db_port = 5432
db_user = odoo
db_password = 123

If you previously relied on environment variables, verify they don’t contain ç and related characters. The variables involved are:

PGHOST
PGPORT
PGUSER
PGPASSWORD
PGDATABASE

When those values are corrected or sanitized, the server should proceed past the cron startup without the UnicodeDecodeError.

Why this matters for Windows-based Odoo stacks

Windows paths, profiles, and hostnames often include accented characters, and they easily slip into service files and environment variables. Database clients like psycopg2 are strict about encodings and will fail early, which is helpful but disruptive if you don’t know where the DSN is assembled. Knowing every place Odoo and psycopg2 look for connection parameters saves hours of guesswork.

Takeaways

When Odoo 18 on Windows crashes with a UnicodeDecodeError from psycopg2 and mentions byte 0xe7, look for the ç character across the full chain of DSN inputs. Check the command-line arguments, the Odoo configuration file, the PG* environment variables, and the Windows PostgreSQL service file under %APPDATA%\postgresql. Keep connection values ASCII or valid UTF‑8, and the server will start cleanly.

The article is based on a question from StackOverflow by Kaue Martins and an answer by Ahrimann Steiner.