Skip to content

Conversation

@moki1202
Copy link
Collaborator

No description provided.

don't know what to enter in the "type" argument and I am still not sure that form_file is the ideal function to replace the POSTFORM function.
@moki1202
Copy link
Collaborator Author

moki1202 commented Mar 14, 2021

@infotroph tried my best to update convert.input file.although I am not at all sure that form_file would be an ideal function to replace POSTFORM function. hhtr::POST might be the ideal choice as you said.

Copy link
Member

@infotroph infotroph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've only looked at convert_input.R so far, but posting this to save my comments and will come back to it as soon as I have time. Thanks for your patience.

out.html <- RCurl::getURL(paste0("http://dap-dev.ncsa.illinois.edu:8184/inputs/",
browndog$inputtype), .opts = curloptions)
out.html <- curl::curl_download(paste0("http://dap-dev.ncsa.illinois.edu:8184/inputs/",
browndog$inputtype), curloptions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested this yet, but it looks correct 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On testing: curl_download writes to disk rather than returning a string. Probably want readLines(curl::curl(..., handle = hdl)), with curl options set beforehand via handle_setopt(hdl, ...)


# post zipped file to Brown Dog
html <- RCurl::postForm(url, fileData = RCurl::fileUpload(zipfile), .opts = curloptions)
html <- curl::form_file(url, type = "___")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the recommended pattern for form posting is to build up the multipart request inside the handle, then pass the whole handle as a fetch. See this example in the curl vignette.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@infotroph thanks for the review ,I'll start working on the other files .

dir.create(basename(file), recursive = TRUE)
count <- 0
while (!RCurl::url.exists(url, .opts = .opts) && count < timeout) {
while (!curl::curl_fetch_memory(url, handle = curl::new_handle(nobody = 1)) && count < timeout) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see two subtleties here:

  • When the url doesn't exist, curl_fetch memory will still return a value that evaluates to TRUE, so we need to explicitly check the status code (e.g. (curl_fetch_memory(...)$status_code %/% 200) == 1)
  • More trickily, when the requested hostname can't be resolved curl_fetch_memory will throw an error whereas RCurl::url.exists just returns FALSE. I'm not sure whether we need to handle this case or not but will ask around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@infotroph should we be using httr:HEAD then?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like httr::HEAD has the same behavior both with respect to status codes and with respect to erroring on unresolvable hostnames, so we don't need to switch because of those. However HEAD definitely shows the intention much clearly than the nobody = 1 incantation does, so it'd be worth using at least in packages that already import httr.

Comment on lines +33 to +35
f <- open(file, mode = "wb")
curl::curl_download(url, file, handle = curl::new_handle(.list = .opts))
close(f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f <- open(file, mode = "wb")
curl::curl_download(url, file, handle = curl::new_handle(.list = .opts))
close(f)
curl::curl_download(url, file, handle = curl::new_handle(.list = .opts))

curl_download handles the opening and closing for us


userpass <- paste(browndog$username, browndog$password, sep = ":")
curloptions <- list(userpwd = userpass, httpauth = 1L, followlocation = TRUE)
result <- RCurl::postForm(paste0(browndog$url, formatname, "/"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is intentionally incomplete for now and will use the same pattern you develop in convert.input, but here's a placeholder to remind us to finish it :)

@infotroph
Copy link
Member

infotroph commented Mar 20, 2021

Input requested: This PR will alter PEcAn.utils::download.url by replacing the call to RCurl::url.exists with a header request performed via curl::curl_fetch_memory, but these behave differently in cases where the host isn't resolvable: url.exists returns FALSE, curl throws an error.

paging @robkooper as architect and @serbinsh as user with an ongoing troublesome retry-the-URL use case: Does download.url need to handle temporary DNS failures, or is it strictly intended to wait for an otherwise-accessible host who is taking a while to prepare a particular file?

[comment edited: Tagged the wrong Kooper.]

@moki1202
Copy link
Collaborator Author

out<-RCurl::curlPerform(url = "https://SDMDataAccess.nrcs.usda.gov/Tabular/SDMTabularService.asmx", httpheader = headerFields, postfields = body, writefunction = reader$update
@infotroph cant really figure out the transformation for this part. can you once explain these arguments (httpheader, writefunction, postfields)?

@infotroph infotroph marked this pull request as draft October 19, 2021 09:51
@mdietze
Copy link
Member

mdietze commented Mar 24, 2022

Similar to comments on other PRs, was curious what's left to do on this one @moki1202 @infotroph

@infotroph
Copy link
Member

@mdietze @moki1202

  1. I tested this locally and discovered I gave some bad advice in the comments above, so I'm fixing in a local branch and will push ASAP.

  2. Branch moki1202/patch-8 has been deleted and getting it back will be a hassle, so I'll open a replacement PR and close this one once it's open.

@moki1202
Copy link
Collaborator Author

@mdietze @moki1202

  1. I tested this locally and discovered I gave some bad advice in the comments above, so I'm fixing in a local branch and will push ASAP.
  2. Branch moki1202/patch-8 has been deleted and getting it back will be a hassle, so I'll open a replacement PR and close this one once it's open.

@infotroph Apologies from my side. Don't know why I deleted this branch. Might have been early days. Let me know how I can help to complete this.

@infotroph infotroph mentioned this pull request Jun 23, 2022
13 tasks
@infotroph
Copy link
Member

Continuing work on this in PR #2944; closing this one

@infotroph infotroph closed this Aug 25, 2022
Copy link
Member

@infotroph infotroph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently LAST YEAR I left a draft review unfinished, including some comments that would have been useful in later conversation. Posting now so they're visible to everyone else, with my apologies.

html <- RCurl::postForm(url, fileData = RCurl::fileUpload(zipfile), .opts = curloptions)
h <- new_handle()
handle_setform(h,
fileData = curl::form_file(curl::curl_upload(zipfile, url))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still getting up to speed on this, but think this line will just be

Suggested change
fileData = curl::form_file(curl::curl_upload(zipfile, url))
fileData = curl::form_file(zipfile)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I was wrong about this... see #2944)

out.html <- RCurl::getURL(paste0("http://dap-dev.ncsa.illinois.edu:8184/inputs/",
browndog$inputtype), .opts = curloptions)
out.html <- curl::curl_download(paste0("http://dap-dev.ncsa.illinois.edu:8184/inputs/",
browndog$inputtype), curloptions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On testing: curl_download writes to disk rather than returning a string. Probably want readLines(curl::curl(..., handle = hdl)), with curl options set beforehand via handle_setopt(hdl, ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants