我在mysql中有一个带有泰米尔语字符的表格。我尝试使用python从表中获取数据,并尝试以json格式打印响应。
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
}
)我在编码utf-8时遇到错误。谁能给我一个基本的例子,让泰米尔语字符作为回应


发布于 2019-04-08 18:44:25
对于Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
dbValue = 'wąską'
tamilValue = dbValue .decode('utf8')
print(tamilValue)Python 3中不需要此声明,因为UTF-8是默认的源编码
对于HTML
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">对于php脚本
header( 'Content-Type: text/html; charset=utf-8' );参考文献:
https://stackoverflow.com/questions/54528278
复制相似问题