Issue
Python 3.8.8 programm with Flask 2.0.1 and Flask-SQLAlchemy 2.5.1
MySql database, collation of the tables: utf8_general_ci. I'm using two other sqlserver DB with SQLALCHEMY_BINDS. Everything runs on Windows 10.
Some chars from select queries on the MySql DB comes wrong: "situazione è decisamente migliorata" should be: "situazione è decisamente migliorata"
This would solve the problem:
mystring.encode('cp1252').decode('utf8')
but I need a solution at program level. I tried:
- appending to SQLALCHEMY_DATABASE_URI connection string: "?charset=utf8" or "?charset=cp1215" and others
- setting app.config['MYSQL_CHARSET'] and app.config['MYSQL_DATABASE_CHARSET'] to 'utf8', 'utf8mb4', 'latin1', 'cp1252' ...
- passing a parameter to SQLAlchemy like db = SQLAlchemy(use_native_unicode="utf8"), many variations here too
No attemp worked. Please I need suggestions.
Solution
Got the solution.
The problem was not a problem. The person who build the original database (that is quite old) coded wrong some characters. Some of my approaches and the one suggested by olegsv, worked, I checked that debugging deep down into into sqlalchemy data structures, the driver accepted the characters encoding, but the very chars in data were themself worong. This was unespected. Maybe I should delete the whole question.
Answered By - chairam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.