Django DatabaseError invalid byte sequence for encoding “UTF8”

Wow this debugging lead me nowhere.

invalid byte sequence for encoding “UTF8”:
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by “client_encoding”.

If you’re getting a DatabaseError, double check that you are not trying to store pickled data through the ORM. The python docs are wrong about pickle protocol 0 being ASCII only and pickle.dumps(u’©∆∂ƒ©˙∆˚’) will output non ASCII.

bug tracked here: http://bugs.python.org/issue2980

Causing a tough to track error at the DB level which does not consistently appear until a “bad” string is passed in.

Leave a Comment