R: unable to download file - r

I wan to download a file using the following request:
request <- 'http://earthserver.ecmwf.int/rasdaman/ows?service=WCS&version=2.0.1&request=ProcessCoverages&query=for c in (geff_fire_weather_index) return encode(c[Lat(35:47),Long(6:18),ansi("2015-01-01T00:00":"2015-12-31T00:00")],"netcdf")'
download.file(url = request, destfile = "rea.nc")
If I run this using the browser it works no problem but in R it fails with the following error message:
downloaded 0 bytes
Error in download.file(url = request2, destfile = "rea.nc") :
cannot download all files
In addition: Warning message:
In download.file(url = request2, destfile = "rea.nc") :
URL 'http://earthserver.ecmwf.int/rasdaman/ows?service=WCS&version=2.0.1&request=ProcessCoverages&query=for c in (geff_fire_weather_index) return encode(c[Lat(35:47),Long(6:18),ansi("2015-01-01T00:00":"2015-12-31T00:00")],"netcdf")': status was 'Couldn't connect to server'
Is there a way to fix this?

Related

Error in downloading the WorldClim data in R using geoData package

I wanted to download the current WorldClim data for the var='bio' for specific tiles. I used the following code to get this done.
bio_curr <- worldclim_tile(var= 'bio', res= 0.5, lon= 5.5, lat = 45.5,
path = "D:/acca files/extra fields/Statistical Analysis/R/SDM analyisis/Ring Ouzel data set")
I got the following error message
trying URL 'https://geodata.ucdavis.edu/climate/worldclim/2_1/tiles/tile/tile_19_wc2.1_30s_bio.tif'
Error in utils::download.file(url = url, destfile = filename, quiet = quiet, :
cannot open URL 'https://geodata.ucdavis.edu/climate/worldclim/2_1/tiles/tile/tile_19_wc2.1_30s_bio.tif'
In addition: Warning message:
In utils::download.file(url = url, destfile = filename, quiet = quiet, :
URL 'https://geodata.ucdavis.edu/climate/worldclim/2_1/tiles/tile/tile_19_wc2.1_30s_bio.tif': Timeout of 900 seconds was reached
Error in .downloadDirect(turl, outfname, ...) : download failed
And I'm a windows user and tried the measure by ticking the TLS 1.2 in internet options advanced settings. It didn't work either
Thanks in advance

Can't install the ggplot2 package

I am trying to install the ggplot2 package I am getting the following errors & warnings.
Warning: failed to download mirrors file (cannot open URL 'https://cran.r-project.org/CRAN_mirrors.csv'); using local file 'C:/PROGRA~1/R/R-42~1.1/doc/CRAN_mirrors.csv'
Error in contrib.url(repos, type) :
trying to use CRAN without setting a mirror
In addition: Warning message:
In download.file(url, destfile = f, quiet = TRUE) :
URL 'https://cran.r-project.org/CRAN_mirrors.csv': status was 'Couldn't connect to server'
> utils:::menuInstallPkgs()
--- Please select a CRAN mirror for use in this session ---
Warning: failed to download mirrors file (cannot open URL 'https://cran.r-project.org/CRAN_mirrors.csv'); using local file 'C:/PROGRA~1/R/R-42~1.1/doc/CRAN_mirrors.csv'
Warning: unable to access index for repository https://repo.miserver.it.umich.edu/cran/src/contrib:
cannot open URL 'https://repo.miserver.it.umich.edu/cran/src/contrib/PACKAGES'
Error in install.packages(lib = .libPaths()[1L], dependencies = NA, type = type) :
argument "pkgs" is missing, with no default
In addition: Warning message:
In download.file(url, destfile = f, quiet = TRUE) :
URL 'https://cran.r-project.org/CRAN_mirrors.csv': status was 'SSL connect error'
> utils:::menuInstallPkgs()
Warning: unable to access index for repository https://repo.miserver.it.umich.edu/cran/src/contrib:
cannot open URL 'https://repo.miserver.it.umich.edu/cran/src/contrib/PACKAGES'
Error in install.packages(lib = .libPaths()[1L], dependencies = NA, type = type) :
argument "pkgs" is missing, with no default
> utils:::menuInstallPkgs()
Warning: unable to access index for repository https://repo.miserver.it.umich.edu/cran/src/contrib:
cannot open URL 'https://repo.miserver.it.umich.edu/cran/src/contrib/PACKAGES'
Error in install.packages(lib = .libPaths()[1L], dependencies = NA, type = type) :
argument "pkgs" is missing, with no default
> utils:::menuInstallPkgs()
Warning: unable to access index for repository https://repo.miserver.it.umich.edu/cran/src/contrib:
cannot open URL 'https://repo.miserver.it.umich.edu/cran/src/contrib/PACKAGES'
Error in install.packages(lib = .libPaths()[1L], dependencies = NA, type = type) :
argument "pkgs" is missing, with no default
> utils:::menuInstallLocal()
> utils:::menuInstallLocal()
Error in utils:::menuInstallLocal() :
Only '*.zip' and '*.tar.gz' files can be installed.
> utils:::menuInstallLocal()
ERROR: dependencies 'digest', 'glue', 'gtable', 'isoband', 'rlang', 'scales', 'tibble', 'withr' are not available for package 'ggplot2'
* removing 'C:/Users/S/AppData/Local/R/win-library/4.2/ggplot2'
Warning message:
In install.packages(files[tarballs], .libPaths()[1L], repos = NULL, :
installation of package ‘C:/Users/S/Documents/ggplot2_3.3.6.tar.gz’ had non-zero exit status
> utils:::menuInstallPkgs()
Warning: unable to access index for repository https://repo.miserver.it.umich.edu/cran/src/contrib:
cannot open URL 'https://repo.miserver.it.umich.edu/cran/src/contrib/PACKAGES'
Error in install.packages(lib = .libPaths()[1L], dependencies = NA, type = type) :
argument "pkgs" is missing, with no default

R: cannot read API call - Error in open.connection(con, "rb")

I can see the contents of the API call in webbrowser, but getting this error with jsonlite package: read_json.
Error in open.connection(con, "rb") : connection cannot be opened
Añso: Warning message:
In open.connection(con, "rb") :
cannot open URL 'https://www.plazavea.com.pe/api/catalog_system/pub/products/search?fq=C:/678/687/&_from=21&_to=41&O=OrderByScoreDESC&': HTTP status was '206 Partial Content'
Code::
library(rvest)
library(tidyverse)
library(jsonlite)
api_request <- "https://www.plazavea.com.pe/api/catalog_system/pub/products/search?fq=C:/678/687/&_from=21&_to=41&O=OrderByScoreDESC&"
product_data <- jsonlite::read_json(api_request)
Use httr and then extract as = 'text' and pass over to parse_json(), or simply specify as = 'parsed' in the content() call on the response object.
library(httr)
api_request <- "https://www.plazavea.com.pe/api/catalog_system/pub/products/search?fq=C:/678/687/&_from=21&_to=41&O=OrderByScoreDESC&"
product_data <- content(httr::GET(api_request), as = 'parsed')

How do I deal with Connection refused error in rvest?

This is my code:
pkgs <- c("rvest", "urltools")
sapply(pkgs, library, character.only = T)
name <- 'cry'
url1 = URLencode(paste0('https://www.google.co.za/search?q=',name))
htmlpage <- html_session(url1)
Unfortunately, I get the following error:
Error in curl::curl_fetch_memory(url, handle = handle) :
Failed to connect to www.google.co.za port 443: Connection refused
What can I do about the error?

Error downloading a csv in zip from website with get in R

I would like to read data from nse-india.com to R using download.file() as shown below.
url = 'http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip'
temp = tempfile()
download.file(url, destfile = temp,method = 'wget')
It throws up following error:
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = C:\PROGRA~2\GnuWin32/etc/wgetrc
--2014-09-28 21:19:26-- http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip
Resolving www.nseindia.com... 202.83.22.200, 202.83.22.203
Connecting to www.nseindia.com|202.83.22.200|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2014-09-28 21:19:26 ERROR 403: Forbidden.
Warning messages:
1: running command 'wget "http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip" -O "C:\Users\ITITHI~1\AppData\Local\Temp\Rtmp2fjADx\file1fb02375882"' had status 1
2: In download.file(url, destfile = temp, method = "wget") :
download had nonzero exit status
Please let me know anyway to fix this.
EDIT: Or any other method to download the file from within R would also be great.
You need to set a browser-like user agent string so the site thinks you're a browser vs an automated scraper/downloader robot:
library(httr) # >=v0.5
GET("http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip",
user_agent("Mozilla/5.0"), write_disk("cm24SEP2014bhav.csv.zip"))
## Response [http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip]
## Date: 2014-09-28 23:53
## Status: 200
## Content-type: application/zip
## Size: 58.2 kB
## <ON DISK> cm24SEP2014bhav.csv.zip
You need permission to access that site. Here is the message (in doc) from the httr package:
url = 'http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip'
doc <- content(GET(url))
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><title>Access Denied</title></head>
<body>
<h1>Access Denied</h1>
You don't have permission to access "http://www.nseindia.com/content/historical/EQUITIES/2014/SEP/cm24SEP2014bhav.csv.zip" on this server.<p>
Reference #18.df24317.1411924047.3b4f02a1
</p>
</body>
</html>

Resources