获取“在未加引号的字段中看到换行符”使用 django-storages 解析 csv 文档时
我正在尝试解析已使用 django-storages 上传到 Amazon S3 的 csv 文件。我不断收到“错误:在未加引号的字段中看到换行符 - 是否需要以通用换行模式打开文件?”。正常的解决方法是使用“rU”打开文件,但这似乎不适用于 django 存储。如果我将文件直接放在服务器上并从那里打开它就可以工作,我只是想尽可能避免将文件直接存储在服务器上。这是我正在使用的代码:
import csv
from django.core.files.storage import default_storage as s3_storage
n = 'csvdumps/130331548894.csv'
csvf = s3_storage.open(n, "rU")
csvReader = csv.reader(csvf)
for item in csvReader:
print item
I am trying to parse csv files that have been uploaded to Amazon S3 using django-storages. I keep getting a "Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?". The normal work around for this is to open the file with "rU", but that does not seem to work with django storages. If I drop the file directly on the server and open from there it works, I just want to avoid storing the files directly on the server if possible. Here is the code I am using:
import csv
from django.core.files.storage import default_storage as s3_storage
n = 'csvdumps/130331548894.csv'
csvf = s3_storage.open(n, "rU")
csvReader = csv.reader(csvf)
for item in csvReader:
print item
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以看到这是 django-storage 报告的错误 http://jgrid.org/david/django-storages/issue/80/trying-to-parse-csv-file-from-django 但也许你可以尝试这个:-
会如果您可以共享一个链接来访问您的一些 S3(示例)csv 文件,那就太好了,这样我就可以打开它们来检查行结尾。
I can see that this is a django-storage reported bug here http://jgrid.org/david/django-storages/issue/80/trying-to-parse-csv-file-from-django but perhaps you can try this:-
Would also be great if you could share a link to access some of your S3 (sample) csv files though so I can open them to check the line endings.