Fix the UNICODE encoding issue while connecting through Pgbouncer after upgrading from 6.21 to 7.1 #6340.

This commit is contained in:
Khushboo Vashi 2023-06-09 16:24:05 +05:30
parent 07fa09f3c7
commit a5b5ede8fd

View File

@ -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')