Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.new("twitter.com", Net::HTTP.https_default_port())

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

like image 860
user1893354 Avatar asked Dec 07 '22 04:12

user1893354


1 Answers

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.

like image 54
spickermann Avatar answered Dec 14 '22 23:12

spickermann