Download.file zip 文件的 URL 从“http:”更改为“https”

问题描述 投票:0回答:1

我有点生疏了,因为我不像以前那样经常使用 R。

我几年前编写的 R 代码在源 URL 从“http:”更改为“https:”时突然停止工作

destfile = "C:/Temp/tmpcftc.zip"
url = "http://www.cftc.gov/files/dea/history/com_disagg_txt_2015.zip"
download.file(url, destfile)
df = read.csv(unz(destfile, "c_year.txt"))

当代码停止工作时,我注意到 URL 更改为“https:”,因此我进行了以下更改:

destfile = "C:/Temp/tmpcftc.zip"
url = "https://www.cftc.gov/files/dea/history/com_disagg_txt_2015.zip"
download.file(url, destfile)
df = read.csv(unz(destfile, "c_year.txt"))

但是,现在我收到以下错误:

trying URL 'https://www.cftc.gov/files/dea/history/com_disagg_txt_2015.zip'
Error in download.file(url, destfile) : 
  cannot open URL 'https://www.cftc.gov/files/dea/history/com_disagg_txt_2015.zip'
In addition: Warning message:
In download.file(url, destfile) :
  InternetOpenUrl failed: 'An error occurred in the secure channel support'

我可以从互联网浏览器下载 URL,没有任何问题,但使用上面的代码却不行。

任何帮助我指明正确方向的帮助将不胜感激。

r rcurl download.file
1个回答
1
投票

我可以重现该错误。我的解决方案是添加行

CURL_SSL_BACKEND=openssl

到 .Renviron 文件。重新启动 R,下载应该可以使用问题中的代码。

© www.soinside.com 2019 - 2024. All rights reserved.