2

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
4

1 回答 1

3

我可以看到这是一个 django-storage 报告的错误http://jgrid.org/david/django-storages/issue/80/trying-to-parse-csv-file-from-django但也许你可以试试这个:-

csvf = s3_storage.open(n.splitlines(), "rU")

如果您可以共享一个链接来访问您的一些 S3(示例)csv 文件,那也很好,这样我就可以打开它们来检查行尾。

于 2011-12-20T03:58:05.590 回答