1

I'm using active_admin_import to import CSV files into active_admin. When uploading the file, I keep getting a "CSV::MalformedCSVError" that states I have an Unclosed quoted field on line xx.

I checked that line, and every line around that line and there are no empty quotes anywhere near it. When I try deleting that line, the error then changes to "Unclosed quoted field on lie 415, and so on.

Error

Here is what my active_admin_import code looks like:

active_admin_import validate: false,
   on_duplicate_key_update: [:description, :price, :notes],
   ignore: [:name, :created_at, :updated_at]
5
  • try to check your CSV file which you going to import this error occur because of format change Commented Jun 14, 2016 at 22:56
  • @uzaif I checked over the CSV file over and over and over, I even deleted the lines that were throwing the errors. Wouldn't it upload the cell data as double-quoted strings? I tried removing instances of single quotes (such as linens'n things) and also tried escaping quotes ( \' ) with no luck Commented Jun 14, 2016 at 23:00
  • try any online CSV file Checker so it will tell you where is problem csvlint.io Commented Jun 14, 2016 at 23:04
  • I just ran it through the linter and it showed zero errors Commented Jun 14, 2016 at 23:30
  • Check the file encoding. If it's encoded in US-ASCII encoding it might throw this error. If that's the case you can open it up in a text editor and re-save it with the correct encoding. This sometimes happens when exporting a CSV file from Excel. Commented Jun 15, 2016 at 2:00

1 Answer 1

1

If anyone stumbles on this, I realized upon converting my CSV to JSON I had a lot of "\r\n" (carriage return and line feed) showing up in my strings that wouldn't display in a CSV file. I got rid of them simply by running

mystr.gsub(/\r\n/," "))

and it removed these errors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.