Reputation: 5139
I created a csv file in Mac Excel and wanna upload it to my server through Django, part of my code in views.py
is as follows:
FILE_UPLOAD_DIR2 = '/mnt/opt/data/spam/'
fd2, filepath2 = tempfile.mkstemp(suffix=request.FILES['spamFile'].name, dir=FILE_UPLOAD_DIR2)
with open(filepath2, 'wb') as dest2:
shutil.copyfileobj(request.FILES['spamFile'], dest2)
But an unexpected error came out: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
I uploaded a csv file created in Windows to my server before and it worked fine, So I guess this may have something to do with the difference of the csv file created in Windows and Mac. Someone has the same problem before?
Upvotes: 2
Views: 6317
Reputation: 17869
I had the exact same issue! It had to do with the way it is saved on a mac! Resave your csv and scroll down and you should see two other kinds of .csv
files you can save it as.
Save it under the windows version and it will now be read fine!!
Upvotes: 8