在httr包中使用GET()时出错

时间:2015-07-28 07:44:30

标签: r web-scraping rcurl httr

我正在使用httr包来访问API。这是我的代码。

Entrez =c(22,10257,10257,55347,10006,102,9508,27125,27125,56894,8540,158798,54890,64682,51433,51479,81573,26057,63926,57182,164,8539,8539,403314,10513,26060,361,378,10565,10565,10565,27236,83478,394,26084,25820,25820,23568,10552,55252,466,1386,64225,64225,23200,79572,84239,488,493,521,10159,8992,528,57198,546,552889,10678,84002,56987,10018,10018,604,9774,54880,8678,659,29117,54014,685,54766,54906,27291,79096,54494,84935,29035,79415,147339,127254,25912,29058,26005,79074,89876,89876,60684,55322,64771,79940,80129,55744,195827,51719,813,821,821,23473,4076,255082,8573)
ids = paste(Entrez,sep="",collapse=",")
type = "ENTREZ_GENE_ID"
tool = "term2term"
annot= "GOTERM_BP_FAT,GOTERM_CC_FAT,GOTERM_MF_FAT"
url = "http://david.abcc.ncifcrf.gov/api.jsp"
library(httr)
data <- GET(url = "http://david.abcc.ncifcrf.gov/api.jsp", query = list(type=type,ids=ids,tool=tool,annot=annot))

如果我在浏览器中手动打开此链接,它的工作原理。但是R给出了以下错误。

Error in function (type, msg, asError = TRUE) : Encountered end of file

这是traceback()

的输出
7: fun(structure(list(message = msg, call = sys.call()), class = c(typeName, 
       "GenericCurlError", "error", "condition")))
6: function (type, msg, asError = TRUE) 
   {
       if (!is.character(type)) {
           i = match(type, CURLcodeValues)
           typeName = if (is.na(i)) 
               character()
           else names(CURLcodeValues)[i]
       }
       typeName = gsub("^CURLE_", "", typeName)
       fun = (if (asError) 
           stop
       else warning)
       fun(structure(list(message = msg, call = sys.call()), class = c(typeName, 
           "GenericCurlError", "error", "condition")))
   }(35L, "Encountered end of file", TRUE)
5: .Call("R_curl_easy_perform", curl, .opts, isProtected, .encoding, 
       PACKAGE = "RCurl")
4: RCurl::curlPerform(curl = handle$handle, .opts = curl_opts$values)
3: perform(handle, writer, method, opts, body)
2: make_request("get", hu$handle, hu$url, config)
1: GET(url = "http://david.abcc.ncifcrf.gov/api.jsp", query = list(type = type, 
       ids = ids, tool = tool, annot = annot))

sessionInfo()

R version 3.1.2 (2014-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] httr_0.6.1

loaded via a namespace (and not attached):
[1] bitops_1.0-6   RCurl_1.95-4.5 stringr_0.6.2  tools_3.1.2  

最终链接

paste("http://david.abcc.ncifcrf.gov/api.jsp","?","type=",type,"&","ids=",ids,"&","tool=",tool,"&","annot=",annot,sep="")
    [1] "http://david.abcc.ncifcrf.gov/api.jsp?type=ENTREZ_GENE_ID&ids=22,10257,10257,55347,10006,102,9508,27125,27125,56894,8540,158798,54890,64682,51433,51479,81573,26057,63926,57182,164,8539,8539,403314,10513,26060,361,378,10565,10565,10565,27236,83478,394,26084,25820,25820,23568,10552,55252,466,1386,64225,64225,23200,79572,84239,488,493,521,10159,8992,528,57198,546,552889,10678,84002,56987,10018,10018,604,9774,54880,8678,659,29117,54014,685,54766,54906,27291,79096,54494,84935,29035,79415,147339,127254,25912,29058,26005,79074,89876,89876,60684,55322,64771,79940,80129,55744,195827,51719,813,821,821,23473,4076,255082,8573&tool=term2term&annot=GOTERM_BP_FAT,GOTERM_CC_FAT,GOTERM_MF_FAT"

如果您尝试在浏览器中打开此链接,则可以使用

0 个答案:

没有答案