Attempting to open https sites in ruby using open-uri gives ssl issue.. How do i resolve?

4.1k views Asked by At

Dug through a lot of documentation and tried monkey patching. Not sure how to force proper certs, nor where to get them. everything works fine with regular http pages. Using Ruby 1.9.3

Here is stacktrace:

C:/Ruby193/lib/ruby/1.9.1/net/http.rb:800:in `connect': SSL_connect returned=1 e
rrno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL
::SSL::SSLError)
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:800:in `block in connect'
        from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:55:in `timeout'
        from C:/Ruby193/lib/ruby/1.9.1/timeout.rb:100:in `timeout'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:800:in `connect'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:756:in `do_start'
        from C:/Ruby193/lib/ruby/1.9.1/net/http.rb:745:in `start'
        from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:306:in `open_http'
        from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:776:in `buffer_open'
        from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:203:in `block in open_loop'
        from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:201:in `catch'
        from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:201:in `open_loop'
        from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:146:in `open_uri'
        from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:678:in `open'
        from C:/Ruby193/lib/ruby/1.9.1/open-uri.rb:33:in `open'
1

There are 1 answers

1
Brad Maynard On BEST ANSWER

When trying to use the open-uri call open you can pass an option to not verify the SSL.

page = Nokogiri::HTML(open(url,{ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE}))