You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言download.file()下载异常:特殊URL引发500服务器错误?

问题解决思路

首先,你遇到的500错误根源是URL格式错误:原URL里重复了域名与协议片段(https://www.naturalearthdata.com/http//www.naturalearthdata.com/...)。浏览器会自动修复这类冗余路径,但R的download.file对URL的容错性较低,因此直接调用会触发服务器错误。

快速修复方案

修正URL,移除重复的http//www.naturalearthdata.com部分,使用正确的地址即可正常下载:

dest <- tempfile()
download.file("https://www.naturalearthdata.com/download/110m/physical/ne_110m_graticules_all.zip",
              dest, mode = "wb")

关于是否需要改用url包

目前不需要优先考虑url包。先修正URL是最直接的解决方式。如果修正后仍存在下载问题(比如服务器反爬、重定向处理),再考虑使用httr或curl这类更精细化的HTTP工具包,示例如下:

library(httr)
dest <- tempfile(fileext = ".zip")
GET("https://www.naturalearthdata.com/download/110m/physical/ne_110m_graticules_all.zip",
    write_disk(dest, overwrite = TRUE))

内容的提问来源于stack exchange,提问作者user111024

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 05:12:15