J
J
jasta312016-08-17 21:37:23
Django
jasta31, 2016-08-17 21:37:23

How to solve utf8 decoding issue when exporting CSV from Django?

I'm using Python 2.7
When uploading a CSV file, there is a problem of the following nature: the data in the file is encoded. f093f94519364ce185e558a0132a996e.png(see screenshot)
My code:

for user in users:
        result = user[0].encode('utf-8')
        for x in filter(lambda q: q is not None, user):
            result += ', '
            if type(x) in (str, unicode):
                result += x.encode('utf-8')
            else:
                result += str(x)
            print type(result), result
        writer.writerow(result)

    return response

Where is the mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question