3
require(data.table)
require(httr)

url = "http://www.dropbox.com/s/0brabdf53lc37i/data.csv?dl=1"
request <- GET(url)


Loading required package: data.table
Loading required package: httr
Error in curl::curl_fetch_memory(url, handle = handle) : 
  Couldn't resolve host name
Calls: GET ... request_fetch -> request_fetch.write_memory ->  -> .Call
Execution halted

What gives? The URL works fine in my browser and others have had success downloading dropbox files this way...

  • 2
    This code just worked for me in my local R console. – Tim Biegeleisen Nov 24 '15 at 03:57
  • @TimBiegeleisen OK thanks, maybe it's a firewall issue or something then...? –  Nov 24 '15 at 03:59
  • 2
    But I could not access the file when I pasted the URL into Chrome. It is some sort of configuration problem. – Tim Biegeleisen Nov 24 '15 at 04:00
  • @TimBiegeleisen Ah, ok, I see. Well, that does narrow it down a bit. I'll have to investigate the configuration of my R session. Thanks. –  Nov 24 '15 at 04:02
  • Loaded fine on my Mac but I see that the first note of the `request` list is `$ url : chr "https://www.dropbox.com/s/0brabdf53lc37i/data.csv?dl=1"` ... so wondering if you have problems with 'https'-sites. – IRTFM Nov 24 '15 at 04:03
  • also take a look at rdrop2 package – OganM Nov 24 '15 at 04:56
  • Code works fine on my console too, as @Tim said, it's likely to be a configuration problem. – Bas Nov 24 '15 at 07:42
  • R changes the URL to `https` before it makes the call. I believe you have an SSL configuration problem. – Tim Biegeleisen Nov 24 '15 at 07:48

2 Answers2

0

I have an answer to your question, after a lot of searching around. When I noticed that R was changing the protocol of your DropBox URL from http to https, I became suspicious that you might have a certificate problem. As this SO post mentions, this seems to precisely be the case. Try using this code:

require(data.table)
require(httr)

cafile <- system.file("CurlSSL", "cacert.pem", package = "RCurl")
url = "http://www.dropbox.com/s/0brabdf53lc37i/data.csv?dl=1"
request <- GET(url, config(cainfo = cafile))

What is happening here:

The cert file cacert.pem contains a list of trusted certificates, issued from a CA (Certificate Authority). When DropBox sends R its public SSL certificate, R will search through this list of trusted certificates to see if it can find it. If it can, it will allow the SSL handshake to complete, and your data will be downloaded.

The reason why you are having this problem but many who read your question do not have it, is that you likely never configured your curl settings in R.

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

The "can't resolve" message is occurring because dropbox is turning your http request into an https request (not all services can follow redirects) and (most likely) because your download protocol can't handle secure http and because the url doesn't request the raw data...

All problems are best fixed by moving to the format the host (dropbox) will direct you too, ie., https, and then switching your code (if necessary) to use the new protocol, and correcting the url to tell dropbox to serve the raw file (not the ?dl=1 suffix you're using, but ?raw=1

So:

  1. switch the url to secure
  2. Switch the request to raw
  3. Test that in a browser - would work if this wasn't a bad link.
  4. Open using R functions like url() that can handle secure transport (example of this is at this answer
Community
  • 1
  • 1
tim
  • 3,559
  • 1
  • 33
  • 46