Re: Getting the SQLSTATE after a failed connection

Ranier Vilela <ranier.vf@gmail.com>

From: Ranier Vilela <ranier.vf@gmail.com>
To: Daniele Varrazzo <daniele.varrazzo@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2025-10-17T17:28:21Z
Lists: pgsql-hackers
Hi.

Em sex., 17 de out. de 2025 às 11:27, Daniele Varrazzo <
daniele.varrazzo@gmail.com> escreveu:

> Hello,
>
> in ticket <https://github.com/psycopg/psycopg/issues/1188> an user
> showed that, upon a failed connection attempt because of a bad
> password, the server sends a SQLSTATE 28P01 message. However psycopg
> cannot raise the expected `InvalidPassword` exception, because the
> only way to get the SQLSTATE seems to be from a PGresult via
> PQresultErrorField and I fail to see any API call to get the info from
> a PGconn.
>
Have you seen the *pgpassfileWarning* function
(src/interfaces/libpq/fe-connect.c)?
Does this sound like what you're looking for?

best regards,
Ranier Vilela