Answer a question

I'm using Python 2.7 and flask framework with flask-sqlalchemy module.

I always get the following exception when trying to insert : Exception Type: OperationalError. Exception Value: (1366, "Incorrect string value: \xF09...

I already set MySQL database, table and corresponding column to utf8mb4_general_ci and I can insert emoji string using terminal.

Flask's app config already contains app.config['MYSQL_DATABASE_CHARSET'] = 'utf8mb4', however it doesn't help at all and I still get the exception.

Any help is appreciated

Answers

It works for me:

 import pickle 
 data = request.get_json().get("data") 
 data = pickle.dumps(data) 

Then you can input the "data" to the database .

You can send the "data" like "😢" ...Whatever emoji you like.

Next time, when you get the "data" from the database :

you should :

data = pickle.loads(data) 

then you can get "data" as "😢"

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐