2

I have created a csv uploader on my rails app, but sometimes I get an error of

"\x9D" to UTF-8 in conversion from Windows-1252 to UTF-8

This is the source to my uploader:

def self.import(file)
  CSV.foreach(file.path, headers: true, encoding: "windows-1252:utf-8") do |row|
    title = row[1]
    row[1] = title.to_ascii
    description = row[2]
    row[2] = description.to_ascii
    Event.create! row.to_hash
  end
end

I am using the unidecode gem (https://github.com/norman/unidecoder) to normalize any goofy characters that a user may input. I've ran into this error a few times, but can't determine how to fix it. I thought the encoding: "windows-1252:utf-8" line would fix the problem, but nothing there.

Thanks stack!

4

1 回答 1

2

Windows-1252中没有 9D 字符(以及 81、8D、8F、90)。这意味着您的文本不是Windows-1252 编码。至少您的源文本已损坏。

于 2013-09-06T16:56:20.713 回答