From 43472c7eb6eedce261c2060f8d1040d87a5e0730 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 21 Aug 2020 18:35:27 -0500 Subject: [PATCH] Use utf8 encoding when downloading results as CSV --- tailbone/views/master.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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):