我问了一个相关的问题,并意识到我没有问正确的问题(即,这不是关于混帐)。
问题是如何在不使用R的情况下在云中创build项目的情况下将项目推送到github。目前,您可以使用RStudio中的git命令行使用此问题的信息完成此操作 。
现在,我正试图从Windows机器上将其转换为R代码(Linux很简单)。 我被困在第一步使用curl从命令行通过R system
调用。 我将显示我有什么,然后错误信息( 感谢SimonO101为了让我这么远 )。 根据他的下面的评论,我已经大量编辑,以反映这个问题,因为它:
R代码:
repo <- "New" user <- "trinker" password <- "password" url <- "http://curl.askapache.com/download/curl-7.23.1-win64-ssl-sspi.zip" tmp <- tempfile( fileext = ".zip" ) download.file(url,tmp) unzip(tmp, exdir = tempdir()) system(paste0(tempdir(), "/curl http://curl.haxx.se/ca/cacert.pem -o " , tempdir() , "/curl-ca-bundle.crt")) cmd1 <- paste0(tempdir(), "/curl -u '", user, ":", password, "' https://api.github.com/user/repos -d '{\"name\":\"", repo, "\"}'") system(cmd1) cmd2 <- paste0(tempdir(), "/curl -k -u '", user, ":", password, "' https://api.github.com/user/repos -d '{\"name\":\"", repo, "\"}'") system(cmd2)
错误消息(两种方法相同):
> system(cmd1) % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 12 0 0 100 12 0 24 --:--:-- --:--:-- --:--:-- 30 100 47 100 35 100 12 65 22 --:--:-- --:--:-- --:--:-- 83{ "message": "Bad credentials" }
我知道所有的文件都在那里,因为:
> dir(tempdir()) [1] "curl-ca-bundle.crt" "curl.exe" "file1aec62fa980.zip" "file1aec758c1415.zip"
它不能是我的密码或用户名,因为这可以在Linux Mint上使用(唯一的区别是curl之前的部分):
repo <- "New" user <- "trinker" password <- "password" cmd1 <- paste0("curl -u '", user, ":", password, "' https://api.github.com/user/repos -d '{\"name\":\"", repo, "\"}'") system(cmd1)
注意:Windows 7机器。 R 2.14.1
编辑 – 在OP提供赏金之后
好吧,事实证明这是一些疯狂的Windows角色在命令行上逃跑。 本质上,问题是我们传递格式不正确的json请求到github。
您可以使用shQuote
正确地格式化Windows的curl请求的有问题的部分。 我们可以测试平台类型,看看是否需要包含特殊格式的Windows例如:
repo <- "NewRepository" json <- paste0(" { \"name\":\"" , repo , "\" } ") #string we desire formatting os <- .Platform$OS.type #check if we are on Windows if( os == "windows" ){ json <- shQuote(json , type = "cmd" ) cmd1 <- paste0( tempdir() ,"/curl -i -u \"" , user , ":" , password , "\" https://api.github.com/user/repos -d " , json ) }
这工作在我的Windows 7框没有任何问题。 我可以更新GitHub脚本,如果你想?
老解答
我在这里和这里做了一些挖掘,可能是你的问题的答案是更新curl-ca-bundle。 它可以帮助Windows获得R使用internet2.dll 。
repo <- "New" user <- "trinker" password <- "password" url <- "http://curl.askapache.com/download/curl-7.23.1-win64-ssl-sspi.zip" tmp <- tempfile( fileext = ".zip" ) download.file(url,tmp) unzip(tmp, exdir = tempdir()) system( paste0( "curl http://curl.haxx.se/ca/cacert.pem -o " , tempdir() , "/curl-ca-bundle.crt" ) ) system( paste0( tempdir(),"/curl", " -u \'USER:PASS\' https://api.github.com/user/repos -d \'{\"name\":\"REPO\"}\'") )
再次,我不能测试这个,因为我没有访问我的Windows框,但更新证书颁发机构文件似乎帮助了一些其他人。 在curl网站上 , curl的Windows版本应该按以下顺序查找curl-ca-bundle.crt
文件: