使用curlPerform或getURL的JSON字符大小限制

时间:2013-04-24 16:18:03

标签: r rcurl

尝试从curlPerform()getURL()检索数据时,我遇到JSON字符串中似乎是字符大小限制的内容。这是不可重现的代码[1],但它应该解决这个问题。

# Note that .base.url is the basic url for the API, q is a query, user 
#  is specified, etc. 
session = getCurlHandle()
curl.opts <- list(userpwd = paste(user, ":", key, sep = ""), 
                  httpheader = "Content-Type: application/json")
request <- paste(.base.url, q, sep = "")
txt <- getURL(url = request, curl = session, .opts = curl.opts, 
              write = basicTextGatherer())

r = dynCurlReader()
curlPerform(url = request, writefunction = r$update, curl = session, 
            .opts = curl.opts)

我的猜测是updatevalue文本处理程序对象中的basicTextGatherdynCurlReader函数在使用大字符串时遇到问题。在此示例中,r$value()将返回大约2 MB的截断字符串。上面给出的代码适用于查询&lt; 2 MB。

请注意,我可以从命令行轻松执行以下操作(或使用R中的system()),但如果我在R中进行后续分析,写入光盘似乎是浪费。

curl -v --header "Content-Type: application/json" --user username:register:passwd https://base.url.for.api/getdata/select+*+from+sometable > stream.json

其中stream.json是一个大约14MB的json字符串。我可以使用

将字符串读入R中
con <- file(paste(.project.path, "data/stream.json", sep = ""), "r")
string <- readLines(con)

或直接列为

tmp <- fromJSON(file = paste(.project.path, "data/stream.json", sep = ""))

非常感谢任何想法。

赖安

[1] - 很抱歉没有提供可重现的代码,但我正在处理政府防火墙。

0 个答案:

没有答案