From: "meta (mathew murphy)" Date: 2012-10-16T04:14:45+09:00 Subject: [ruby-core:48011] [ruby-trunk - Bug #7156] Invalid byte sequence in US-ASCII when using URI from std lib Issue #7156 has been updated by meta (mathew murphy). What part of the URL contains the UTF-8 characters? If it's the domain, you need to decode the UTF-8 into punycode before passing it to Ruby. It it's in the path, Ruby ought to handle it for IRI compliance, but probably doesn't right now... http://www.w3.org/International/articles/idn-and-iri/ ---------------------------------------- Bug #7156: Invalid byte sequence in US-ASCII when using URI from std lib https://bugs.ruby-lang.org/issues/7156#change-30788 Author: t0d0r (Todor Dragnev) Status: Open Priority: Normal Assignee: Category: lib Target version: ruby -v: 1.9.3 Invalid byte sequence in US-ASCII on ruby 1.9.3 I receive that error when trying to open url with bulgarian text (utf-8: "��������������"). It seems that the problem is in uri/common.rb from ruby standard library... adding str.force_encoding(Encoding::BINARY) to following method fix the problem class URI::Parser def escape(str, unsafe = @regexp[:UNSAFE]) unless unsafe.kind_of?(Regexp) # perhaps unsafe is String object unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false) end str.force_encoding(Encoding::BINARY) # FIX str.gsub(unsafe) do us = $& tmp = '' us.each_byte do |uc| tmp << sprintf('%%%02X', uc) end tmp end.force_encoding(Encoding::US_ASCII) end end One more suggestion - maybe US_ASCII must be replaced to Encoding::BINARY too? -- http://bugs.ruby-lang.org/