From a5b5ede8fd9e466ba22fa192834ca52f0f5947ea Mon Sep 17 00:00:00 2001 From: Khushboo Vashi Date: Fri, 9 Jun 2023 16:24:05 +0530 Subject: [PATCH] Fix the UNICODE encoding issue while connecting through Pgbouncer after upgrading from 6.21 to 7.1 #6340. --- web/pgadmin/utils/driver/psycopg3/encoding.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web/pgadmin/utils/driver/psycopg3/encoding.py b/web/pgadmin/utils/driver/psycopg3/encoding.py index 3597a813b..ee8daacf0 100644 --- a/web/pgadmin/utils/driver/psycopg3/encoding.py +++ b/web/pgadmin/utils/driver/psycopg3/encoding.py @@ -10,6 +10,7 @@ # Get Postgres and Python encoding import psycopg +from flask import current_app encode_dict = { 'SQL_ASCII': ['SQL_ASCII', 'raw-unicode-escape'], @@ -33,7 +34,12 @@ def get_encoding(key): # if key == 'ascii': key = 'raw_unicode_escape' - postgres_encoding = psycopg._encodings.py2pgenc(key).decode() + try: + postgres_encoding = psycopg._encodings.py2pgenc(key).decode() + except Exception as e: + # For unsupported encodings by psycopg like UNICODE + current_app.logger.error(e) + postgres_encoding = 'utf-8' python_encoding = psycopg._encodings._py_codecs.get(postgres_encoding, 'utf-8')