Ruby 1.9 - Invalid Multibyte Char (Us-Ascii)

Invalid multibyte char with Ruby 1.9, setting encoding: utf-8 does not fix it

Use a tool such as od (assuming you're on Linux) to look at the actual contents of the file. If you have single byte C5, your file isn't in UTF-8. It's probably stored in ISO-8859-1 or similar, and Ruby is quite correctly complaining.

Ruby error invalid multibyte char (US-ASCII)

When you run the script with Ruby 1.9, change the first two lines of the script to:

#!/usr/bin/env ruby
# encoding: utf-8
require 'net/http'

This tells Ruby to run the script with support for the UTF-8 character set. Without that line Ruby 1.9 would default to the US_ASCII character set.

Just for the record: This will not work in Ruby 1.8, because 1.8 doesn't knew anything about string encodings. And the line is not needed anymore in Ruby 2.0, because Ruby 2.0 is using UTF-8 as the default anyway.

Ruby 1.9 - invalid multibyte char (US-ASCII)

Write # encoding: utf-8 on top of that file. That changes the default encoding of all string/regexp literals in that file utf-8. The default encoding for all literals is US-ASCII, which cannot represent á.

Rails 3 invalid multibyte char (US-ASCII)

Instead of adding # coding: UTF-8 try to add # encoding: UTF-8 on the first line of the file.

It worked for me. I found the information here : http://groups.google.com/group/sinatrarb/browse_thread/thread/f92529bf0cf62015

VSCode complains a Ruby UTF-8 file has invalid multibyte char (US-ASCII)

I think the issue is in the linter.

"ruby.lint": {
"reek": true,
"rubocop": true,
"ruby": {
"unicode": true,
},
"fasterer": true,
"debride": false,
"ruby-lint": false
},

in settings.json unicode is not turned on by default for ruby.lint so you need to do that manually.

invalid multibyte char (US-ASCII) in a chef recipe

The line in the code :

 initdb –D  –-no-locale –-encoding=UTF8

Should be:

 initdb –D  --no-locale --encoding=UTF8

Ruby invalid multibyte char error (Sep 2019)

I could reproduce your issue by saving the file with ISO-8859-1 encoding.

Running your code with the file in this non UTF8-encoding the error popped up. My solution was to save the file as UTF-8.

I am using Sublime as text editor and there is the option 'file > save with encoding'. I have chosen 'UTF-8' and was able to run the script.

Using puts line.encoding showed me UTF-8 then and no error anymore.

I suggest to re-check the encoding of your saved script file again.

Invalid multibyte char (US-ASCII) error for ä, ü, ö, ß which are Ascii!

Put the magic comment # coding: utf-8 at the beginning your your script (on the second line if you're using shebang).

#!/usr/local/bin/ruby
# coding: utf-8

puts "i like my chars: ä, ü, ö and ß!"


Related Topics



Leave a reply



Submit