kroe761 kroe761 - 1 year ago 128
Ruby Question

Ruby / RestClient.get returning certificate verify failed

I am trying hit an internal testing api server using Ruby's RestClient (Ruby version 2.2.1). This is essentially the code:

url = ""
header = {
:content_type => "application/json",
:"x-auth-token" => "testingtoken"
response = RestClient.get url, header

This is the failure message I get:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (RestClient::SSLCertificateNotVerified)

If I'm reading this right, it looks like Ruby couldn't accept the SSL security certificate. Now, this call works in the Chrome app Postman, but in order for it to work, I have to hit the url in Chrome itself, accept that the connection is not secure (but proceed anyways), and THEN it will work in postman. Is there anyway to ignore the certificate failures and proceed anyways in Ruby? Thanks!

Answer Source

Try using #execute(&block) with verify_ssl set to false.

:verify_ssl enable ssl verification, possible values are constants from OpenSSL::SSL::VERIFY_*, defaults to OpenSSL::SSL::VERIFY_PEER

url = ""
headers = {
  :content_type => "application/json",
  :"x-auth-token" => "testingtoken"

  :url => url, 
  :method => :get, 
  :headers => headers,
  :verify_ssl => false



Additional solution for RVM users from:

This discussion on Github [] finally gave the solution: Somehow RVM comes with a precompiled version of ruby that is statically linked against an openssl that looks into /etc/openssl for it's certificates.

What you wanna do is NOT TO USE any of the precompiled rubies and rather have ruby compiled on your local machine, like so: rvm install 2.2.0 --disable-binary