utf-8 でエンコードされた xml を ExpatParser インスタンスにフィードすると、次のようになります。
def test(filename):
parser = xml.sax.make_parser()
with codecs.open(filename, 'r', encoding='utf-8') as f:
for line in f:
parser.feed(line)
...次のようになります。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.py", line 72, in search_test
parser.feed(line)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/xml/sax/expatreader.py", line 207, in feed
self._parser.Parse(data, isFinal)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb4' in position 29: ordinal not in range(128)
私はおそらくここで明らかな何かを見逃しています。パーサーのエンコーディングを「ascii」から「utf-8」に変更するにはどうすればよいですか?