SSL connect error in httr / curl

AndrewMacDonald picture AndrewMacDonald · Jan 28, 2016 · Viewed 14.4k times · Source

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

  • confirmed that this is the most recent version of libcurl3 for Ubuntu 14.04
  • checked the ssl certificate using openssl as in this answer
  • uninstalled/reinstalled curl, RCurl and httr
  • confirmed that this DOES work from the terminal:

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))

Answer

AndrewMacDonald picture AndrewMacDonald · Jan 28, 2016

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")