From 5e093495aa710c25ee427e33d5d64ec8d05acc91 Mon Sep 17 00:00:00 2001 From: "Andrew G. Brown" Date: Tue, 4 Oct 2022 12:15:17 -0700 Subject: [PATCH] fetchKSSL: Fix for "status was 'SSL connect error" - use curl internally and use standard soilDB curl handle including ssl_verifyhost=0 --- R/fetchKSSL.R | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/R/fetchKSSL.R b/R/fetchKSSL.R index 131d393b..e9d55977 100644 --- a/R/fetchKSSL.R +++ b/R/fetchKSSL.R @@ -46,13 +46,15 @@ .getExtended_SoilWeb <- function(f) { # KSSL geochem, XRD, glass - extended.url <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=extended', f)) - + x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=extended', f)) + + tf <- tempfile() + curl::curl_download(x, tf, quiet = TRUE, mode = "wb", handle = .soilDB_curl_handle()) + ## get data - # note: missing data are returned as FALSE by the API - # when data are available, list of data.frame objects - ext <- jsonlite::fromJSON(gzcon(url(extended.url))) - # unlink(tf) + # list of dataframe objects; note: missing data are returned as FALSE + ext <- jsonlite::fromJSON(gzfile(tf)) + unlink(tf) # done return(ext) @@ -62,13 +64,16 @@ .getMorphologic_SoilWeb <- function(f) { # NASIS morphology - morph.url <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=nasis_morphologic', f)) + x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=nasis_morphologic', f)) + tf <- tempfile() + curl::curl_download(x, tf, quiet = TRUE, mode = "wb", handle = .soilDB_curl_handle()) + ## get data - # note: missing data are returned as FALSE - # list of dataframe objects - m <- jsonlite::fromJSON(gzcon(url(morph.url))) - + # list of dataframe objects; note: missing data are returned as FALSE + m <- jsonlite::fromJSON(gzfile(tf)) + unlink(tf) + # done return(m) } @@ -78,13 +83,16 @@ .getKSSL_SoilWeb <- function(f) { # KSSL site + horizon - site_hz.url <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=site_hz', f)) - - # ## get data - # # note: missing data are returned as FALSE - # # list of dataframe objects - site_hz <- jsonlite::fromJSON(gzcon(url(site_hz.url))) + x <- URLencode(paste0('https://casoilresource.lawr.ucdavis.edu/soil_web/kssl/query.php?gzip=1&format=json&what=site_hz', f)) + tf <- tempfile() + curl::curl_download(x, tf, quiet = TRUE, mode = "wb", handle = .soilDB_curl_handle()) + + ## get data + # list of dataframe objects; note: missing data are returned as FALSE + site_hz <- jsonlite::fromJSON(gzfile(tf)) + unlink(tf) + # report missing data if( all(