I'm currently running into some serious issues with ruby, the google geocoding api, and openssl. I'm running Mac OS X 10.11.3, rvm 1.27.0 and ruby 2.2.2. The openssl version is the problem.
The issue appears when I'm trying to access google's geocoding service with my api key, which requires ssl. No matter whether I use result = Geocoder.search("Some Address, USA"),
or a more typical HTTParty.get("https://maps.googleapis.com/maps/api/geocode/json?address=Some+Address+US&key=MyApiKey)"
, I am still getting an error.
The error is
/Users/me/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:923:in 'connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
, as well as backtrace to the Geocoder.search()
function.
I've seen that lots of people have openssl issues with ruby, so I checked openssl version
and it returns OpenSSL 0.9.8zg 14 July 2015
. I followed the advice of this post (http://railsapps.github.io/openssl-certificate-verify-failed.html) and ran rvm osx-ssl-certs update all
, as well as reinstalling openssl with homebrew, but even after all of that my terminal says that openssl is already up to date. At this point it seems obvious that I have two installations of openssl, the old 0.98 in /usr/bin/
and the other where homebrew keeps its installations. My last attempt to fix the problem was to run brew link openssl --force
, but I get this error:
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
How do I link the ruby compiler with homebrew's version of ssl? Do I have to do this manually every terminal session?
As simpler version of the script I've written would be this
require 'geocoder'
require 'HTTParty'
Geocoder.configure(
:google => {
:api_key => "AIzaSyAG_TrgufZrrNTiwwBu2NP_xCXy3OGsH7M"
})
address = "350 5th Ave, New York, NY"
result = Geocoder.search(address)
print result