为什么我会收到“FasterCSV :: MalformedCSVError:Illegal quoting error”?

时间:2013-05-14 11:47:42

标签: ruby ruby-on-rails-3 fastercsv

我用这个让我自己有点疯狂。

我正在尝试导入CSV文件:

uploaded_io = File.read("amazon_import.csv")
FasterCSV.parse(uploaded_io, {:headers => true, :quote_char => '"', :col_sep => "\t"}).each do |row_data|

  new_record = AmazonSale.new(
    'asin' => row[0],
    'title' => row[1],
    'barcode' => row[2].match(/\d+/),
    'price' => row[4],
    'discount' => row[5],
    'cost' => row[7],
    'active' => row[8],
    'product_group' => row[9],
    'release_date' => row[10],
    'customer_ordered_units' => row[11],
    'shipped_units' => row[12],
    'shipped_date' => Date.today - 1,
    'shipped_cogs' => row[14],
    'sellable_on_hand_units' => row[15],
    'unsellable_on_hand_units' => row[16],
    'customer_owned' => row[17],
    'total_inventory_units' => row[18],
    'vendor_units_received' => row[19],
    'open_po_qty' => row[20],
    'two_week_forecast' => "",
    'four_week_forecast' => "",
    'category' => "",
    'subcategory' => "",
    'author' => row[25],
    'binding' => "",
    'platform' => "",
    'cat_no' => row[28]
  )
  new_record.save
end

我在我的应用程序中的其他地方成功使用了几乎相同的脚本,但是这个脚本会抛出错误:

FasterCSV::MalformedCSVError: Illegal quoting in line 70.

违规行似乎:

0711297466621,£,5.56,20,£,4.45,Active,Music,06/10/2003,2,5,£,22.25,0,0,4,4,1,27,Alternative & Indie,Unknown,"Bragg, Billy",Audio CD,cd,COOKCD266,,

我可以看到它是“Bragg,Billy”造成这种情况并尝试了所有类型的东西来逃避或删除逗号和引号但我一直得到同样的错误。

有人可以帮忙吗?

我在Ruby 1.8.7上。

0 个答案:

没有答案