Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSL connect error in httr / curl

Tags:

r

httr

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

like image 329
AndrewMacDonald Avatar asked Jan 28 '16 07:01

AndrewMacDonald


People also ask

What causes SSL connection error?

An SSL certificate error occurs when a web browser can't verify the SSL certificate installed on a site. Rather than connect users to your website, the browser will display an error message, warning users that the site may be insecure.


2 Answers

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

like image 56
AndrewMacDonald Avatar answered Oct 05 '22 02:10

AndrewMacDonald


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.
like image 43
Jeroen Ooms Avatar answered Oct 05 '22 01:10

Jeroen Ooms