9

I tried the following code in R on windows:

library(RCurl)
postForm("https://www.google.com/accounts/ClientLogin/",
    "email" = "me@gmail.com",
    "Passwd" = "abcd",
    "service" = "finance",
    "source" = "Test-1"
)

but go the following error:

Error in postForm()
SL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

How do I setup RCurl to allow use of HTTPs?

Zach
  • 29,791
  • 35
  • 142
  • 201
  • 1
    More of a guess than an answer, but does `curlVersion()$protocol` include "https"? If not, then you need to install a version of the curl library with ssl support. How to do that would depend on your operating system (the output of `sessionInfo()` might help) – Martin Morgan Jul 18 '11 at 23:36

2 Answers2

13

just add .opts = list(ssl.verifypeer = FALSE) to your query

postForm("https://www.google.com/accounts/ClientLogin/",
    "email" = "me@gmail.com",
    "Passwd" = "abcd",
    "service" = "finance",
    "source" = "Test-1",
    .opts = list(ssl.verifypeer = FALSE))
Pak
  • 147
  • 1
  • 4
  • 2
    This answer is dangerously incorrect. You should not disable verification that the connection is valid without fully understanding the implications of that decision. – TARehman Mar 20 '18 at 16:02
12

You need to install a SSL library.

  1. For windows you can get one here: Download "OpenSSL for Windows" version 0.9.8k

  2. Unzip to a temporary folder, and copy the files "libeay32.dll" and "ssleay32.dll" from the "bin" sub-folder to R\library\RCurl\lib\i386.

  3. Also you might copy it into the same directory as the R.exe.

  4. Then check if you have access to the https protocol:

    library(RCurl)
    curlVersion()$protocol 
    ## [1] "tftp"   "ftp"    "telnet" "dict"   "ldap"   "http"   "file"   "https"     
    ## [9] "ftps"   "scp"    "sftp"  
    
  5. Then install a new set of credential files:

    ca-bundle.crt can be found at : http://curl.haxx.se/ca/cacert.pem

    rename / copy to ca-bundle.crt

  6. Test with this:

    getURL("https://www.google.com/accounts/ClientLogin/?service=finance&email=me@gmail.com&Passwd=abcd&source=Test-1", 
           cainfo = "path to R/library/RCurl/CurlSSL/ca-bundle.crt")
    
Thomas
  • 43,637
  • 12
  • 109
  • 140
Mischa Vreeburg
  • 1,576
  • 1
  • 13
  • 18
  • Thanks! Very nicely explained. – Arun Jun 20 '15 at 12:28
  • @Mscha Vreeburg, I followed your steps, I get this error: Error in function (type, msg, asError = TRUE) : error setting certificate verify locations: CAfile: C:/Users/Documents/R/win-library/3.2/RCurl/CurlSSL/ca-bundle.crt CApath: none – user1471980 Dec 13 '16 at 19:06