SSL connect error in httr / curl

15,937

Solution 1

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.

Solution 2

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

Share:
15,937
AndrewMacDonald
Author by

AndrewMacDonald

I'm interested in insects, birds and ecology. I'm a PhD student at the University of British Columbia.

Updated on June 16, 2022

Comments

  • AndrewMacDonald
    AndrewMacDonald almost 2 years

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

  • Nicholas
    Nicholas over 8 years
    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.
  • user5249203
    user5249203 over 7 years
    Thank you, it helped me.