特定のエンコーディング 16 進数を含まない Unicode 文字列を印刷しようとしています。UTF-8 の html ヘッダーにエンコーディング タイプを持つ facebook からこのデータを取得しています。タイプを印刷すると、Unicodeと表示されますが、unicode-escapeでデコードしようとすると、エンコードエラーがあると表示されます。デコード メソッドを使用するとエンコードしようとするのはなぜですか?
コード
a='really long string of unicode html text that i wont reprint'
print type(a)
>>> <type 'unicode'>
print a.decode('unicode-escape')
>>> Traceback (most recent call last):
File "scfbp.py", line 203, in myFunctionPage
print a.decode('unicode-escape')
UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 1945: ordinal not in range(128)