Prevent 'ArgumentError: invalid byte sequence in UTF-8' on Faraday[Ruby]


This is a tips to prevent “ArgumentError: invalid byte sequence in UTF-8“.

🚌 Sample Code

url = "http://sample.com/search?q=%A0"

Faraday.get(url)
ArgumentError: invalid byte sequence in UTF-8

Faraday.get(url.force_encoding(Encoding::BINARY))
=> #<Faraday::Response:0x007fd8ca826ce8...

Happy Hacking!


🏈 Special Thanks

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!