I am reading CSV file from the remote location and then parsing it to store into the local collection, however, I am getting following error and the response is getting as some garbage characters
Encoding::UndefinedConversionError: "\xD0" from ASCII-8BIT to UTF-8
Here is code to fetch the csv from the remote location
uri = URI.parse(site_url)
data = {'token' => "xxxxxxxxxxxxxx"}
req = Net::HTTP::Get.new(uri.path)
req.set_form_data(data)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme =='https'
pem = File.read("#{Rails.root}/config/ca-certificates.crt")
http.use_ssl = true
http.cert = OpenSSL::X509::Certificate.new(pem)
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
response = http.start do |httpvar|
httpvar.request(req)
end
if response.kind_of?(Net::HTTPRedirection)
headers = {'Content-Type' => "text/csv; ecoding=utf-8" }
uri = URI.parse(response['location'])
response = open(uri).read
end
CSV.parse(response, headers: true, header_converters: :symbol) do |row|
puts row
end