CSV - Unquoted fields do not allow \r or \n (line 2)

后端 未结 8 1338
耶瑟儿~
耶瑟儿~ 2020-12-28 15:38

Trying to parse a CSV file, but still getting the error message Unquoted fields do not allow \\r or \\n (line 2)..

I found here at SO similar topic,

8条回答
  •  庸人自扰
    2020-12-28 16:21

    For me I was importing LinkedIn CSV and got the error.

    I removed the blank lines like this:

      def import
        csv_text = File.read('filepath', :encoding => 'ISO-8859-1')
        #remove blank lines from LinkedIn
        csv_text = csv_text.gsub /^$\n/, ''
        @csv = CSV.parse(csv_text, :headers => true, skip_blanks: true)
      end
    

提交回复
热议问题