0

I have the Flask application which shows the address of a person. I have stored text in Hindi in MySQL in address column. When I am fetching data using query it is displaying proper text. Refer below

mysql> select address from addresses where id=1;

Output: शहर (proper Hindi text)

But when I am fetching(from MySQL) the same data using Flask app, My browser is showing this type of text

यà¤à¥à¤à¤¤à¤¾à¤ªà¥à¤°à¤® 

I am not able to get the exact data that is stored in the database. If it is a problem in MySQL then why I am getting proper text when running query.

I have set(below) in Flask

app.config['MYSQL_CHARSET'] = 'utf8mb4' 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

is also set in all HTML files.

I have tried all the solutions from stack overflow but no success. Given below are the properties of MySQL table(for ref)

mysql> show create table addresses;

CREATE TABLE `addresses` (
  `id` varchar(128) NOT NULL,
  `address` varchar(512) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

mysql> SHOW VARIABLES LIKE 'collation%';


+----------------------+--------------------+
| Variable_name        | Value              |
+----------------------+--------------------+
| collation_connection | utf8mb4_unicode_ci |
| collation_database   | utf8_general_ci    |
| collation_server     | utf8mb4_unicode_ci |
+----------------------+--------------------+

Its been a week I am trying to solve this but no result. Please help!

Elliot
  • 174
  • 3
  • 11
  • 1
    A [mojibake](https://en.wikipedia.org/wiki/Mojibake) case of the following kind: `"हिन्दी शहर".encode( 'utf-8').decode( 'cp1252','ignore')` returns `'हिनà¥à¤¦à¥€ शहर'`. It's irreversible due to the `ignore` error handler. Configure _flask_ properly. – JosefZ Feb 08 '21 at 17:14
  • Also check `SHOW VARIABLES LIKE 'char%';` and the connection parameters. More on "Mojibake": https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Feb 27 '21 at 17:12
  • Do `SELECT col, HEX(col) FROM ...` so we can see if it is irreversible. – Rick James Feb 27 '21 at 17:16

0 Answers0