我用R编写了一个程序并进行了一些分析。数据是由具有JSON格式的MongoDB的外部供应商捕获的。他们通过端口443上的URI向我提供它,他们希望我使用cURL进行查询。它们具有身份验证和自签名SSL。
我可以在Windows中通过curl对数据进行身份验证和转储,但是要创建一个长期可持续的解决方案,需要在R.
供应商说RCurl“应该”工作,但他们没有提供任何支持,他们只是根本不喜欢使用RMongo的想法,对此没有任何评论(但我认为,如果我们能让它正常工作,那就太棒了)。
我已经加载了以下包- ggplot2 - DBI - rjson -rjson- RJSONIO (如果我使用rjson,或者visa相反,有时我不会加载这个包)- RMongo - rstudio - RCurl
即使使用curl,自签名的证书也会导致问题,但是这些问题可以通过在Ruby中编辑设置,然后用Ruby启动cmd shell并以这种方式使用curl来解决。我不确定R中的问题是否相关。
在尝试使用RCurl路由时,我会得到如下命令/错误:
x <- getURL("https://xxx.xx.xxx.xxx:443/db/_authenticate", userpwd="xxxx:xxxxx") }{Error in function (type, msg, asError = TRUE) : couldn't connect to host当我试图使用RMongo的时候,我甚至更加无知.
> mongo <- mongoDbConnect("xxx.xx.xxx.xxx")用户名= "xxxx“password="xxxxxxxxxxxxx”身份验证<- dbAuthenticate(mongo,用户名,密码)2月25日,2013年4:00:09 PM com.mongodb.DBTCPConnector fetchMaxBsonObjectSize警告:确定maxBSON大小的异常using0 java.io.IOException:无法连接到/127.0.0.1:27017 bc:java.net.ConnectException:连接被拒绝:连接在com.mongodb.DBPort.open(DBPort.java:224) at com.mongodb.DBPort.go(DBPort.java:101) at com.mongodb.DBPort.go(DBPort.java:82) at com.mongodb.DBPort.findOnecom.mongodb.DBPort.runCommand(DBPort.java:151) at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:429) at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:416) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:193) at com.mongodb.DBApiLayer$MyCollection._find(DBApiLayer.java:303) at com.mongodb.DB.command(DB.java:159)com.mongodb.DB.command(DB.java:144) at com.mongodb.DB._doauth(DB.java:503) at com.mongodb.DB.authenticate(DB.java:440) at rmongo.RMongo.dbAuthenticate(RMongo.scala:24)
Error in .jcall(rmongo.object@javaMongo, "Z", "dbAuthenticate", username, :
com.mongodb.MongoException$Network: can't call something
Feb 25, 2013 4:00:10 PM com.mongodb.DBPortPool gotError
WARNING: emptying DBPortPool to 127.0.0.1:27017 b/c of error
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:224)
at com.mongodb.DBPort.go(DBPort.java:101)
at com.mongodb.DBPort.go(DBPort.java:82)
at com.mongodb.DBPort.call(DBPort.java:72)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:202)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:303)
at com.mongodb.DB.command(DB.java:159)
at com.mongodb.DB.command(DB.java:144)
at com.mongodb.DB._doauth(DB.java:503)
at com.mongodb.DB.authenticate(DB.java:440)
at rmongo.RMongo.dbAuthenticate(RMongo.scala:24)任何帮助都将不胜感激!
发布于 2013-02-26 15:02:01
过去,我在RCurl上遇到了一个问题,我需要将它显式地指向安全证书,以使它正常工作。最后我需要这样的东西:
out <- postForm("https://url.org/api/",
token="IMATOKEN",
.opts=curlOptions(cainfo="C:/path/aaa.crt"))我已经手动导出了我需要的证书。
而且,考虑到这个URI,而不是GET,您应该做一个POST请求。也许可以试试postForm()命令?
编辑后添加:
好吧,我想如果我们退后一步,事情可能会更清楚一些。你的目标是从一个特定的URL (基本上,做一个wget,但在R内)获得一些文件吗?还是您的目标是提交一个随后返回所需数据的表单?
如果您只是想获得一些基本(也相当不安全)的HTTP身份验证,那么您应该做两件事:
代码:
getURL("http://www.omegahat.org/RCurl/testPassword/",.opts=list(userpwd="bob:welcome"))
OR
getURL("http://bob:welcome@www.omegahat.org/RCurl/testPassword/")现在,如果您需要提交一个表单来获取数据,您通常会将身份验证令牌等作为参数传递(因此,在上面的示例中,‘tokens =’)。
https://stackoverflow.com/questions/15079321
复制相似问题