diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 5a36bcb9..68ae7615 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -1935,11 +1935,16 @@ class MasterView(View): for obj in results: writer.writerow(self.get_csv_row(obj, fields)) response = self.request.response - response.body = data.getvalue() + if six.PY3: + response.text = data.getvalue() + response.content_type = 'text/csv' + response.content_disposition = 'attachment; filename={}.csv'.format(self.get_grid_key()) + else: + response.body = data.getvalue() + response.content_type = b'text/csv' + response.content_disposition = b'attachment; filename={}.csv'.format(self.get_grid_key()) data.close() response.content_length = len(response.body) - response.content_type = b'text/csv' - response.content_disposition = b'attachment; filename={}.csv'.format(self.get_grid_key()) return response def results_xlsx(self):