Search code examples
rmacoscurlrcurlhttr

RCurl on OS X El Capitan -9806 Error


I am trying to use RCurl for an oauth 2 authentication. My code is:

library(RCurl)
myOpts <- curlOptions(httpheader =  
      c(Accept="application/json",
    "Content-Type"="application/x-www-form-urlencoded"))

token <- postForm(authURL, 
    .params = list(
        client_id ="aaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
        client_secret = "bbbbbbbbbbbbbbbbbbbbbbbbbbbb",
        username = "xxxxx@yyyy.zzz",
        password = pswd), 
    .opts = myOpts, 
    style="POST")

The code works just fine on R/Windows, but not on OS X El Capitan. On OS X, I get the error

Error in function (type, msg, asError = TRUE)  : 
SSLRead() return error -9806

I think it is a problem with SSL in the version of curl/libcurl that ships with OS X, and is documented elsewhere, but I haven't been able to figure out a fix. For what it's worth, I had similar problems with the httr package. How do I update curl and make it play nicely with RCurl?

My question is quite similar to How do I get RCurl to connect to POST SSL on OS X Yosemite?, but El Capitan has made it difficult to copy the curl-config file as suggested in the answer to that post.


Solution

  • I got the following to work:

    1. Install libressl from source using the usual gnu configure/make/install sequence.
    2. Install curl from source again using the usual gnu configure/make/install sequence. At the configure step, I needed to use the --with-ca-bundle option to point configure to a valid certificate file.
    3. Compile RCurl from source making sure /usr/local/bin comes earlier in the path list than /usr/bin so that RCurl's configure script finds curl-config from the new version of curl rather than from the os x default version.

    I'd love to know if there's a better way.