From 7c0d13eb05bf9acc71afec43a95cbce6e20b844e Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Wed, 20 Oct 2021 13:16:42 +0200 Subject: [PATCH] Fix wrong error message on unknown PostgreSQL encoding Reported in #122. --- psycopg/psycopg/_encodings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/psycopg/psycopg/_encodings.py b/psycopg/psycopg/_encodings.py index 705e1cadf..0d917466a 100644 --- a/psycopg/psycopg/_encodings.py +++ b/psycopg/psycopg/_encodings.py @@ -88,4 +88,6 @@ def pg2pyenc(name: Union[bytes, str]) -> str: try: return py_codecs[name] except KeyError: - raise NotSupportedError("codec not available in Python: {name!r}") + if isinstance(name, bytes): + name = name.decode("utf8", "replace") + raise NotSupportedError(f"codec not available in Python: {name!r}") -- 2.47.2