Mac中的Django中的csv文件上传错误:在无引号字段中看到的新行字符 [英] csv file uploading error in Django in Mac: new-line character seen in unquoted field

查看:284
本文介绍了Mac中的Django中的csv文件上传错误:在无引号字段中看到的新行字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac Excel中创建了一个csv文件,并希望通过Django将其上传到我的服务器, views.py 中的部分代码如下:

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?

我在Windows中创建的csv文件已经上传到我的服务器,所以我想这可能与在Windows和Mac中创建的csv文件的差异有关。有人有同样的问题吗?

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?

推荐答案

我有同样的问题!它与它在Mac上保存的方式有关!重新保存您的csv并向下滚动,您应该看到另外两种 .csv 文件,您可以将其保存为。

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.

将其保存在windows版本下,现在可以阅读了。

Save it under the windows version and it will now be read fine!!

这篇关于Mac中的Django中的csv文件上传错误:在无引号字段中看到的新行字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆