monkinetic weblog

Steve Ivy's Weblog - Since 1999 - XII Ed.

Python, Unicode, Ascii, Encodings

I've been working on a python-based app for a week or so now (on and off) and I've run into a spate of problems I don't know how to handle.

I'm getting RSS data in (I'm told) UTF-8 from the server. It's aggregated data, so there's no telling the source. Some of it is international (Japanese I think) and I'm having a crap time getting python to work with it. It oughta work, as I understand it, but all I get is:

UnicodeDecodeError: 'ascii' codec can't 
decode byte 0xe2 in position 2: ordinal 
not in range(128)

I've tried a few things with various encodings, but I'm not grokking something. Anyone with either text encoding or python experience have any ideas?

Oh, all I'm doing with it is pouring it into a template using

UNICODE_TEMPLATE_TEXT % (mystery_text)

My name is Steve Ivy and I write about technology, the open web, social software, and general nerdity on monkinetic.com. You should follow me on Twitter or subscribe to this blog if you like what you're reading. I spend my days hacking Movable Type, python, Django, and various other efforts at Wallrazer. This is my personal site.