0
votes

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.

2
Can you post the definition of class M? - Petr Viktorin

2 Answers

4
votes

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

4
votes

Most likely your comment column should be of type Unicode instead of String.