I have a Python 2 Pyramid web app using SQLAlchemy to talk to a MySQL table, of which all string columns are UTF-8 encoded. When I pull the data to display, I must use .decode("UTF-8")
in order for it to show, otherwise I get the natural error of ASCII can not decode.
I have two questions:
Is there any other way of working to avoid the need of
.decode("UTF-8")
each and every time?If I want to push something into the database, and I have a string which is
s = u'str'
, do I need to do anything to it when it's to be insterted to a UTF-8 column?
Thank you very much.
For people who might find this message through a google search: If you encounter an error, sort of:
UnicodeDecodeError: 'ascii' codec can't decode byte in
Do use
.encode(..)