【发布时间】:2012-02-16 04:15:40
【问题描述】:
我正在尝试学习如何将具有 https url 的 access/zip 文件读入 R。这是我正在进行的一个更大的映射学习项目的一部分,以扩展我发现的 R 技能HERE (我也会把这篇文章链接回去).
这是计划,但我从 getURL 收到错误,我不知道为什么:
require(RCurl)
NYSdemo <- getURL("https://reportcards.nysed.gov/zip/SRC2010.zip")
temp <- tempfile()
download.file(NYSdemo, temp)
data <- read.table(unz(temp, "a1.dat"))
unlink(temp)
错误:
> NYSdemo <- getURL("https://reportcards.nysed.gov/zip/SRC2010.zip")
Error in function (type, msg, asError = TRUE) :
SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
就像我说的,这是一个学习项目,所以我在这里使用的许多技术我都不熟悉。
我要下载的实际 zip 文件是 HERE
也许这实际上不是编程问题,而是 URL 有问题,无法在其上使用 getURL。
提前感谢您的想法和帮助。
编辑:我尝试了 ssl.verifypeer 但又遇到了一个错误
> NYSdemo <- getURL("https://reportcards.nysed.gov/zip/SRC2010.zip",
+ ssl.verifypeer = FALSE)
Error in curlPerform(curl = curl, .opts = opts, .encoding = .encoding) :
embedded nul in string: 'PK\003\004\024\0\0\0\b\0i[j>¶U#]tó\036\005\0 ÷- {And it continues}
>
编辑 2:Per Vincent 的建议
> NYSdemo <- getURL("http://reportcards.nysed.gov/zip/SRC2010.zip")
> download.file(NYSdemo, temp)
Error in download.file(NYSdemo, temp) : unsupported URL scheme
>
> NYSdemo <- getBinaryURL("https://reportcards.nysed.gov/zip/SRC2010.zip")
Error in function (type, msg, asError = TRUE) :
SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
>
> url.exists("https://reportcards.nysed.gov/zip/SRC2010.zip")
[1] FALSE #not sure why this is because it works to type into url bar of browser
这些信息让我相信问题出在 zip 文件中。想法?
【问题讨论】:
-
错误信息说无法验证网站的身份。您可以尝试通过将
https替换为http来绕过这些检查(但连接变得不安全)。您可能还需要将getURL替换为getBinaryURL。 -
@Vincent Zoonekynd 感谢您的回复。我尝试了你的建议(见编辑 2)但没有运气。
-
您原来的错误很容易修复。真正的问题是您第一次编辑中的错误。 > 块引用“curlPerform 中的错误(curl = curl,.opts = opts,.encoding = .encoding):字符串中嵌入 nul:'PK\003\004\024\0\0\0\b\0i[j>¶ U#]tó\036\005\0 ÷- {它继续}" 这是需要修复的区域,但我不知道该怎么做。其他人会,但我敢肯定。
-
如果您在
getURL之后不再有错误消息,则它起作用了,并且文件的内容在NYSdemo变量中。download.file与getURL做同样的事情(所以你不需要两者),并期望一个 URL 作为参数:download.file("http://...")。 -
@Vincent 我认为它不起作用,因为 getURL 之后 NYSdemo 的内容给出:
[1] "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>302 Found</title>\n</head><body>\n<h1>Found</h1>\n<p>The document has moved <a href=\"https://reportcards.nysed.gov/zip/SRC2010.zip\">here</a>.</p>\n</body></html>\n"我不认为我想要这个。
标签: r