I’m using Pyramid and SQLAlchemy, but the following simplified code:
u = u"\u201C"
m = M()
m.comment = u
m.user_id = 1
session.add( m )
session.commit()
gives me a
UnicodeEncodeError: 'latin-1' codec can't encode character u'\u201c' in position 0: ordinal not in range(256)
what do I need to fix this?
edit:
comment is a “MEDIUMTEXT” column, MySQL type.
Check to see if your database’s tables are encoded with an encoding other than unicode.
Also, if you want your comments be readable from phpMyAdmin (or whatever you are using to connect to your DB) you should append:
?charset=utf8&use_unicode=0
to your connection string in the application configuration file
so you’d have mysql://user:pass@localhost/dbname?charset=utf8&use_unicode=0