Forums

Encoding Hell

My value in the database looks like this:

£40

This is part of a longer sentence, in case anyone asks why I'm storing it like this.

When I render the text (Flask/Jinja2/Python2.7.9) I get it like this:

\xc2\xa340

Why is this?

My call function looks like this:

def content_brief_metadata(self):
    try:
        self.cursor.execute("set names utf8;")
        self.cursor.execute('select title, description from metadata')
        return self.cursor.fetchall()
    except Exception as e:
        return e
    finally:
        self.db.close()

I just pass the data to the template and that's it.

I've also got the charset of the template to utf-8.

Been fighting with this all night.

I figured this out - I just needed to decode. However, I was displaying my string inside a list which wasn't escaping properly so had me going round in circles.

Glad you worked it out! I must admit that the better unicode support was the things that made come to love Python 3...