:ssl.connect() always returns :socket_options error!

Hi!

What is the right way of calling the :ssl.connect() ? From Erlang -- Using SSL application API it looks like it should be:

:ssl.start() 
:ssl.connect("google.com", 443, [{:verify, :verify_peer},{:cacerts, :public_key.cacerts_get()}])

But no matter what host or options I try, I get the same:


Interactive Elixir (1.14.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :ssl.start()                                                                                      
:ok
iex(2)> :ssl.connect("google.com", 443, [{:verify, :verify_peer}, {:cacerts, :public_key.cacerts_get()} ])
{:error,
 {:options,
  {:socket_options,
   [packet_size: 0, packet: 0, header: 0, active: false, mode: :binary]}}}

Does anyone know what am I doing wrong?
Thanks!

Since :ssl is an erlang lib I expect you would need to put the URL in single quotes for Elixir, like 'google.com'. That may not be the source of the error you are seeing but it might help.

1 Like

Yup

iex(3)> :ssl.connect("google.com", 443, [{:verify, :verify_peer},{:cacerts, :public_key.cacerts_get()}])
{:error,
 {:options,
  {:socket_options,
   [packet_size: 0, packet: 0, header: 0, active: false, mode: :binary]}}}
iex(4)> :ssl.connect('google.com', 443, [{:verify, :verify_peer},{:cacerts, :public_key.cacerts_get()}])
{:ok,
 {:sslsocket, {:gen_tcp, #Port<0.7>, :tls_connection, :undefined},
  [#PID<0.244.0>, #PID<0.243.0>]}}

It’s a common gotcha when transliterating code from Erlang to Elixir.

2 Likes

Thanks!! That was exactly it! :slight_smile:

1 Like