使用download.file时

时间:2016-11-28 22:39:17

标签: r download passwords special-characters

我正在尝试使用download.file功能下载文件。我使用的URL受密码保护。但我的密码中有多个特殊字符,不允许我下载我的文件。有没有办法可以在不更改密码的情况下绕过这个?

我使用的密码包含特殊字符'$''@'

下面是我得到的示例和错误代码。

download.file("http://myusername:P@$$word@myurl.com?$format=json", myfile.json, method = "auto")

'InternetOpenUrl失败:'服务器名称或地址无法解析'

1 个答案:

答案 0 :(得分:1)

尝试对密码中的字符进行编码:

password <- "P@$$sword"
password <- URLencode(password, reserved=TRUE)  # deal with @ and $

file.loc <- sprintf("http://myusername:%s@myurl.com?format=json", password)
download.file(file.loc, ...)