I am developing an application in python with django. User can download CSV file. I use file upload to get the file. But he does not store anywhere. I am trying to take it from a request to process a file. While I try to open the file, it gives an error. I am using the CSV library existing in python for processing. Form elements and attributes used for django. The request object that I am trying to load the downloaded file is also an object created by django.
import csv from rootFolder.UploadFileForm def uploadFile(request): if request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): paramFile = open(request.FILES['uploadFile'], 'rb') portfolio = csv.DictReader(paramFile) users = [] for row in portfolio: users.append(row)
The line below indicates the error.
paramFile = open(request.FILES['uploadFile'], 'rb')
This error:
TypeError: coercing to Unicode: need string or buffer, InMemoryUploadedFile found
Please kindly give your suggestion if you have an idea about this. Thanks in advance.
Nazneen
source share