3

I have a table in mysql with tamil characters. Using python i attempted to fetch data from the table, and tried to print the response in json format.

def train_masters_live():
        questions = request.args.get('question').encode('utf8')
        print("testing", (questions))
        conn = mysql.connect()
        cursor = conn.cursor()
        cursor.execute("select answers from tamil_service")
        result = cursor.fetchone()
        print(result)
        return jsonify(
             {
                  "data":result
             }
        )

i am getting error while encoding utf-8. Can someone give me a basic example to get tamil character as a responseenter image description here

enter image description here

Thara
  • 281
  • 3
  • 14
  • Are you sure if the encoding is UTF-8 ? I will suggest to use SQL Alchemy module over sqlite. There is possibility that the characters are not getting properly decoded. – Akash Patil Feb 05 '19 at 06:12

1 Answers1

0

For Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-

dbValue = 'wąską'
tamilValue = dbValue .decode('utf8')
print(tamilValue)

This declaration is not needed in Python 3 as UTF-8 is the default source encoding

For HTML

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

For php script

header( 'Content-Type: text/html; charset=utf-8' );

References:

https://stackoverflow.com/a/6289494

https://stackoverflow.com/a/1198713

Bala555
  • 119
  • 1
  • 6