title: OpenUri causing 401 Unauthorized error with HTTPS URL
body: <p>I am adding functionality that scrapes an XML page from a source that requires the use of an HTTPS connection with authentication. I am trying to use Ryan Bates' Railscast #190 solution but I'm running into a 401 Authentication error.</p>
  
  <p>Here is my test Ruby script:</p>
  
  <pre><code>require 'rubygems'
  require 'nokogiri'
  require 'open-uri'
  
  url = "https://biblesearch.americanbible.org/passages.xml?q[]=john+3:1-5&amp;version=KJV"
  doc = Nokogiri::XML(open(url, :http_basic_authentication =&gt; ['username' ,'password']))
  puts doc.xpath("//text_preview")
  </code></pre>
  
  <p>Here is the output of the console after I run my script:</p>
  
  <pre><code>/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `block in connect'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in `connect'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:744:in `start'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:306:in `open_http'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:775:in `buffer_open'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:203:in `block in open_loop'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:201:in `catch'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:201:in `open_loop'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:146:in `open_uri'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:677:in `open'
  from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/open-uri.rb:33:in `open'
  from scrape.rb:6:in `&lt;main&gt;'
  </code></pre>
  
  <p>In my research, I saw one post in which it was suggested that in 1.9.3 the following option could be used: </p>
  
  <pre><code>doc = Nokogiri::XML(open(url, :http_basic_authentication =&gt; ['username' ,'password'], :ssl_verify_mode =&gt; OpenSSL::SSL::VERIFY_NONE))
  </code></pre>
  
  <p>However, this did not work either. I would appreciate some insight into addressing this challenge.</p>