9

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

Community
  • 1
  • 1
AndrewMacDonald
  • 2,870
  • 1
  • 18
  • 31
  • I've just ran into this problem too. Using curl at the command line seems to work fine, but not from R. According to `curl_version()` I'm using version 7.22.0. – Nicholas Jan 28 '16 at 12:42
  • I cannot reproduce this. Is this error still occurring? – Thomas Jan 28 '16 at 13:37
  • I suspect SSLv3 problem. Can you please include output of `curl::curl_fetch_memory("https://api.openaq.org/v1/countries", new_handle(verbose=T))` – Jeroen Ooms Jan 28 '16 at 14:38

3 Answers3

10

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

AndrewMacDonald
  • 2,870
  • 1
  • 18
  • 31
6

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.
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
  • Yes, I can confirm it's due to some issue with using GnuTLS instead of OpenSSL. The problem occurred on my laptop with curl package 0.9.5 and curl version 7.22.0, where `curl_version()$ssl_version` shows it's using GnuTLS/2.12.14. It all seems OK on another machine with the same curl package and version, but where OpenSSL/1.0.1 is used. I wonder why. – Nicholas Jan 28 '16 at 21:33
2

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!

Kevin Woo
  • 101
  • 1
  • 4