]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Fix wrong error message on unknown PostgreSQL encoding
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 20 Oct 2021 11:16:42 +0000 (13:16 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 20 Oct 2021 11:23:39 +0000 (13:23 +0200)
Reported in #122.

psycopg/psycopg/_encodings.py

index 705e1cadfa5248cd92fd59af1297e930264e7bbb..0d917466a4ee36e1df1bc98d338633fd00678dfc 100644 (file)
@@ -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}")