0

I have the Flask application which shows the address of a person. I have stored Hindi text 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
  • 47
  • 2
  • 5
  • Pretty sure is because it’s trying to map your Hindi characters to ASCII, which won’t work. You’ll probably need to define your output to be UTF 8, similar to this question: https://stackoverflow.com/questions/14772275/utf-8-text-hindi-not-getting-displayed-on-browser-window-or-eclipse-console – JerseyDevel Feb 02 '21 at 04:58
  • `िर` is Mojibake; see https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Feb 02 '21 at 05:34
  • @Lkabo - Question marks has a different cause and cure than Mojibake, so I disagree with your suggested link. – Rick James Feb 02 '21 at 05:42
  • @RickJames वà¥à¤¯à¤à¥à¤à¤¤à¤¾à¤ªà¥à¤ this is the full text I am getting, in sql it is storing as hindi only, but when I fetch from sql and showing in web its getting like this, do u think still i need to CHARACTER SET utf8 in column feild? is it the problem with My db? – Elliot Feb 02 '21 at 06:02
  • @Elliot - Please tell me what that string should be saying; It does not work in the way I expected it to work. – Rick James Feb 02 '21 at 07:37

0 Answers0