user1893354 user1893354 - 1 year ago 283
Ruby Question

Ruby error invalid multibyte char (US-ASCII)

I am trying to run the ruby script found here

but I am getting the error

invalid multibyte char (US-ASCII)

for line 12 which is

http ="", Net::HTTP.https_default_port())

can someone please explain to me what this means and how I can fix it, thanks

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download