UnicodeDecodeError when using Python 2.x unicodecsv
I'm trying to write out a csv file with Unicode characters, so I'm using the unicodecsv package. Unfortunately, I'm still getting UnicodeDecodeErrors: # -*- coding: utf-8 -*- import codecs import unicodecsv raw_contents = 'He observes an “Oversized Gorilla” near Ashford' encoded_contents = unicode(raw_contents, errors='replace') with codecs.open('test.csv', 'w', 'UTF-8') as f: w = unicodecsv.writer(f, encoding='UTF-8') w.writerow(["1", encoded_contents]) This is the traceback: Traceback (most recent call last): File "unicode_test.py", line 11, in <module> w.writerow(["1", encoded_contents])