[R] RCurl: using netrc with curlPerform

Valerie Obenchain vobencha at fhcrc.org
Wed Aug 27 03:20:35 CEST 2008


Hello,

I am having trouble getting the curlPerform function to authenticate 
using the .netrc file. From the documentation I've read it
certainly seems as though this function should be able to authenticate 
via the .netrc file. 

The example I am using here comes from the "R as a Web Client- the RCurl 
package" paper and demonstrates using the .netrc file to access the 
www.omegahat.org page. Authentication takes place by RCurl (curl) 
reading the username and password out of the .netrc file in the user's 
home directory. For this example the username is bob and password is 
welcome. The .netrc file in the user's home directory contains the 
following information:
machine www.omegahat.org
login bob
password welcome


I can successfully use the .netrc file with the getURL function:
 > getURL("http://www.omegahat.org/RCurl/testPassword/index.html", netrc=1)

[1] "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n<html> 
<head>\n<title>Basic Password Test</title>\n</head>\n\n<body>\n<h1>Basic 
Password Test</h1>\nThis is a test page.\nIf you can read it, you have 
correctly supplied\nthe password.\n\n\n<hr>\n<address><a 
href=\"http://stat.ucdavis.edu/~duncan\">Duncan Temple Lang</a>\n<a 
href=mailto:duncan at wald.ucdavis.edu>&lt;duncan at wald.ucdavis.edu&gt;</a></address>\n<!-- 
hhmts start -->\nLast modified: Sun Aug  1 13:57:44 PDT 2004\n<!-- hhmts 
end -->\n</body> </html>\n"


When I try to do the same with the curlPerform function I get an error 
saying that the curl option is not recognized. I have tried 3 different
ways of instructing the curlPerform function to use the .netrc file (in 
the .opts, curl handle and the ... argument) but got the same error 
message each time.

# Failed attempt using .opts construct
myopts <-curlOptions(netrc=1)
curlPerform("http://www.omegahat.org/RCurl/testPassword/index.html", 
.opts=myopts)

# Failed attempt using curl handle
handle <- getCurlHandle(netrc=1)
curlPerform("http://www.omegahat.org/RCurl/testPassword/index.html", 
curl=handle)

# Failed attempt using ... construct
curlPerform("http://www.omegahat.org/RCurl/testPassword/index.html", 
netrc=1)

Common error message for all failed attempts:
Error in mapCurlOptNames(names(.els), asNames = TRUE) :
  Unrecognized CURL options:


Valid curl option names are listed by typing listCurlOptions() and netrc 
is one of the options. The mapCurlOptNames code is not available
for the user to view so I'm not able to deduce anything more from the 
error message.


Thanks,
Valerie



More information about the R-help mailing list