打开远程csv无法正常工作

时间:2016-08-13 19:26:32

标签: ruby-on-rails csv

所以我有一个rake任务试图像这样打开一个csv文件。

task priceupdate: :environment do
  csvtoopen = open('http://www.someurlhere.com/feed.csv')
  csv = CSV.foreach(csvtoopen, :headers=>true)
  csv.each do |row|
    #Stuff to do with rows here
  end
end

出于某种原因,当我运行此任务时,它无法正常工作。 (它应该将每行添加到db(适用于其他任务))

我碰巧遇到了这个错误:

CSV::MalformedCSVError: Illegal quoting in line 1.

非常感谢任何帮助。

修改 继续前几行

"CategoryID","CategoryName","CategoryURL","EventID","EventName","EventDate","EventURL","Venue","VenueCity","VenueCountryCode","VenuePostcode","CurrentMinPrice","CurrentMaxPrice","CurrentTickets","PreSaleDate","OnSaleDate","SoldOutDate","CategoryImageURL","CategoryDescription","VenueAddress","VenueState","VenueID","AffiliatesCommissionTier","TopLevelCategory"
"1478","The Gruffalo"

萨姆

1 个答案:

答案 0 :(得分:0)

问题在于CSV文件clang 3.8

文件第一行中有一个前导空格。这就是为什么ruby抱怨第1行的gcc

要亲自查看,请点击http://api.viagogo.net/feeds/ukeventfeed.csv