diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 6ebeecac..aea4be67 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -27,6 +27,7 @@ Model Master View from __future__ import unicode_literals, absolute_import import os +import csv import datetime import tempfile import logging @@ -2720,8 +2721,13 @@ class MasterView(View): results = results.with_session(session).all() fields = self.get_csv_fields() - csv_file = open(path, 'wt') - writer = UnicodeDictWriter(csv_file, fields) + if six.PY2: + csv_file = open(path, 'wb') + writer = UnicodeDictWriter(csv_file, fields, encoding='utf_8') + else: # PY3 + csv_file = open(path, 'wt', encoding='utf_8') + writer = csv.DictWriter(csv_file, fields) + writer.writeheader() def write(obj, i):