0

If I want to download a clone as a zip, it does a redirect.

zip.url = "https://github.com/MonteShaffer/humanVerse/archive/refs/heads/main.zip"

redirects to:

<html><body>You are being <a href="https://codeload.github.com/MonteShaffer/humanVerse/zip/refs/heads/main">redirected</a>.</body></html>

I am trying to using the RCurl library:

require(RCurl)
curl.fun = basicTextGatherer();
curl.ch = getCurlHandle();

x = getBinaryURL(zip.url, curl = curl.ch, headerfunction = curl.fun$update )

One windoze 10, throwing this error:

Error in function (type, msg, asError = TRUE)  : 
  error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

I am assuming github is doing multiple redirects. I want to download the file as a binary 'zip'.

Dharman
  • 30,962
  • 25
  • 85
  • 135
mshaffer
  • 959
  • 1
  • 9
  • 19

1 Answers1

2

You have to set the curl option followlocation to TRUE, like this:

binary_blob <- RCurl::getBinaryURL(zip.url, .opts = list(followlocation = TRUE))

It might be easier to download the file instead with the following two options:

utils::download.file() comes with R and works for this.

zip.url <- "https://github.com/MonteShaffer/humanVerse/archive/refs/heads/main.zip"

download.file(zip.url, "main.zip")

The curl package has curl_download().

library(curl)
curl::curl_download(zip.url, "main2.zip")
Till
  • 3,845
  • 1
  • 11
  • 18
  • Very nice, comprehensive answer. I am looking for a ```base::R``` solution. It downloads the same 1KB redirect file using either `Rcurl` or `download.file` ... I have libcurl enabled. My codebase would work, but it appears there is something with SSL/TLS going on. I get the same error using the `followlocation` flag. – mshaffer Apr 20 '21 at 21:52
  • `curl::curl_download()` and `download.file()` both work for me, I get the zip archive (on Linux). I guess something is "special" with your setup. – Till Apr 20 '21 at 23:27
  • I wonder if it has something to do with my 'git bash' ... Seems unlikely, but ... https://stackoverflow.com/questions/48944875 – mshaffer Apr 20 '21 at 23:37
  • Seems like this URL works no problem: `https://codeload.github.com/MonteShaffer/humanVerse/legacy.tar.gz/main` – mshaffer Apr 21 '21 at 01:46