How to fix "bad URI(is not URI?)"

Tagged uri, url, ruby, parse  Languages ruby

This URL contains special characters, which Ruby can't handle:

>> URI.parse 'ästra_Finland/Askainen/varsel.xml'
URI::InvalidURIError: bad URI(is not URI?):ästra_Finland/Askainen/varsel.xml
    from /usr/local/lib/ruby/1.8/uri/common.rb:436:in split'
    from /usr/local/lib/ruby/1.8/uri/common.rb:485:in parse'
    from (irb):5

Your browser can probably open the URL. To fix this error encode the URL before handing it to the parse method:

=> #<URI::HTTP:0x18bfb40 URL:>