Quantmod Error 'cannot open URL'

社会主义新天地 提交于 2019-11-26 18:29:18

问题


I started to experience an error today with the quantmod package. Anybody else have the same error when running this code (or requesting symbols in general)?

library(quantmod) getSymbols("CPIAUCNS",src="FRED")

Error:
Error in download.file(paste(FRED.URL, "/", Symbols[[i]], "/", "downloaddata/", : cannot open URL 'http://research.stlouisfed.org/fred2/series/CPIAUCNS/downloaddata/CPIAUCNS.csv'

The URL itself works fine.


回答1:


FRED changed the URL scheme from http:// to https://. I'm working on determining a patch that will work on all platforms. The current code still works for me on Windows if --internet2 is set.

On unix-alikes, one potential solution is to add method="curl" or method="wget" to the download.file call in getSymbols.FRED.




回答2:


Another (temporary) solution is to call one of the following before the actual getSymbols script:

options(download.file.method="libcurl")
or
options(download.file.method="wget")
or
options(download.file.method="wininet")

The first option works for me (on Mac).
Thanks Paul Gilbert from Rmetrics (bottom post)




回答3:


The problem appeared yesterday:
Cannot verify certificate for stlouisfed.org issued by GoDaddy.

A workaround:

temp = tempfile()

download.file(url="http://research.stlouisfed.org/fred2/series/DAAA/downloaddata/CPIAUCNS.csv",destfile=temp, method="libcurl")

result <- read.csv(temp,na.string=".")

I hope having to use this fix is temporary.




回答4:


Here is solution that works for me, assuming you trust FRED's SSL certificate.

All you need to do is adding the following extra line of code before executing getSymbols:

options(download.file.method = "wget", download.file.extra = c("--no-check-certificate"))

Example:

getSymbols("M2", from = start_date, to = end_date, src = "FRED")

[1] "M2"

str(M2)

An ‘xts’ object on 1980-11-03/2015-10-05 containing: Data: num [1:1823, 1] 1591 1593 1596 1597 1596 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr "M2" Indexed by objects of class: [Date] TZ: UTC xts Attributes:
List of 2 $ src : chr "FRED" $ updated: POSIXct[1:1], format: "2015-10-21 11:01:39"



来源:https://stackoverflow.com/questions/31188023/quantmod-error-cannot-open-url

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!