AndrewMacDonald
AndrewMacDonald

Reputation: 2950

SSL connect error in httr / curl

I'm trying to access an open API with httr, and having no luck. Whenever I try:

httr::GET("https://api.openaq.org/v1/countries")

I get the following error:

Error in curl::curl_fetch_memory(url, handle = handle) : 
   SSL connect error

However, other connections to https work just fine, for example

httr::GET("https://httpbin.org/get")

Here is the output of sessionInfo():

R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS

locale:
 [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8    
 [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8   
 [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
[1] httr_1.0.0.9000 R6_2.1.2        tools_3.2.3     curl_0.9.5     

At terminal, if I run curl-config --version I get

libcurl 7.35.0

updates: things I have tried

curl -v "https://api.openaq.org/v1/countries"

I cannot understand how the command-line curl works fine, but curl in R fails

more updates -- verbose doesn't work

I've tried getting more info from R by asking httr to be verbose. It produces the identical error:

httr::GET("https://api.openaq.org/v1/countries", httr::verbose()) Error in curl::curl_fetch_memory(url, handle = handle) : SSL connect error same with httr::GET("https://api.openaq.org/v1/countries", httr::verbose(ssl=TRUE))

Upvotes: 12

Views: 22761

Answers (3)

Kevin Woo
Kevin Woo

Reputation: 331

I'm using R-4.3.1 and work in a corporate network with SSL intercept. I encountered this 'SSL connect error' and reverted to using install.packages("some_package", method="wininet"). While wininet works, it is a bit slow. Here's my new workaround:

  • Removed the wininet workaround to revert back to the default libcurl
  • Added the following line to my .Rprofile
    • Sys.setenv(R_LIBCURL_SSL_REVOKE_BEST_EFFORT=TRUE)

I learnt this via the following references:

I hope this helps!

Upvotes: 9

AndrewMacDonald
AndrewMacDonald

Reputation: 2950

Solved this (with assistance from @Jeroen and richfitz)

First I ran the following in the terminal:

sudo apt-get install libcurl4-openssl-dev

then uninstalled and reinstalled curl in R:

install.packages("curl")

Upvotes: 10

Jeroen Ooms
Jeroen Ooms

Reputation: 32978

The SSL handshake fails. Some potential reasons:

  • You compiled with gnutls instead of openssl. Try: apt-get install libcurl4-openssl-dev.
  • Your libcurl is really outdated and does not support the TLS version required by the server.

Upvotes: 6

Related Questions