1. Computing

Mechanize Error: Mechanize::UnsupportedSchemeError

By

What Causes the Error?

The error Mechanize::UnsupportedSchemeError is raised when Mechanize tries to fetch a page using an unsupported protocol scheme, such as ftp or gopher. Mechanize supports only the file, http and https schemes.

This error can also manifest itself in the form of an ArgumentError with the message "unsupported scheme: #{uri.scheme}", where uri.scheme is the scheme of the URL you attempted to access.

How do I Fix The Error

Unfortunately, there's not much that can be done to fix this error. Mechanize can only access URLs beginning in http://, https:// and file://. All other schemes and protocols are unsupported. The best thing you can do is catch the error and try to handle it gracefully, or if you're really out of options, let the error fall through.


agent = Mechanize.new

begin
  page = agent.get('gopher://gopher.example.com')
  #...
rescue Mechanize::UnsupportedSchemeError => e
  puts "Found link with unsupported scheme, trying another"
  #...
end
See More About
  1. About.com
  2. Computing
  3. Ruby
  4. Tutorials
  5. The Mechanize 2.0 Handbook
  6. Mechanize Error: Mechanize::UnsupportedSchemeError

©2014 About.com. All rights reserved.