Erro: (status 400) Invalid parameter. how to solve?

install.packages("rcoreoa")
install.packages("RCurl")
library(rcoreoa)
library(RCurl)

setwd("D:/EECA/INICIACAO_CIENTIFICA/")

CORE_KEY= "7rIUuYomD51JXjEKNypFnGhZWV68zgdB" # Recebida por email...

QUERY = data.frame("all_of_the_words" = "warming global",
"find_those_words" = "b",
"language" = "en",
"year_from" = "2017",
"year_to" = "2019")

RES = data.frame(ID=character(),
Author_1st=as.character(),
Title=as.character(),
Year=as.character(),
Description=as.character(),
Download_link=as.character())

last = round(core_advanced_search(query = QUERY, key = CORE_KEY)$totalHits/100)

for (pp in 1:2){
res = core_advanced_search(query = QUERY,
key = CORE_KEY,
page = pp,
limit = 100)

RES = rbind(RES,
data.frame(ID = res$data$_source$id,
Author_1st = unlist(lapply(res$data$_source$authors, function(x) x[1])),
Title = res$data$_source$title,
Year = res$data$_source$year,
Description = unlist(res$data$_source$description),
Download_link = res$data$_source$downloadUrl)
)
}

who = which(RES$Download_link != "" & RES$Description != "")
RES = RES[who,]

write.csv2(RES,"warming.csv", row.names = FALSE)
RES = read.csv2("warming.csv")

for (i in 1:nrow(RES)){
my_filename =
my_destfile = paste("D:/EECA/INICIACAO_CIENTIFICA/ARTIGOS/V2/",
RES$Author_1st[i],
" (",RES$Year[i],").pdf", sep="")
my_url = as.character(RES$Download_link[i])
if (url.exists(my_url)){
download.file(url = my_url,
destfile = my_destfile,
mode = "wb")
}
}

The difficulty derives from execution of

When provided to the server, the URL is malformed for purposes of the cgi. You can confirm this with HTTP access from a browser by cut-and-pasting a representative value of my_url.

To debug, make the same query by hand. From a successful result, conform the structure of my_url

I'm new to this language, could you help me get this information?
how should write the code in r to get this information?

Thank's

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

Thank you for return. But, error is variable last. What is the problem?

Can't tell without seeing the HTTP request passed through my_url and what a well-formed HTTP request passed through a browser looks like

If this were a Google query search for 404 code, you would have an URL like this

https://www.google.com/search?client=ubuntu&channel=fs&q=404+code+error&ie=utf-8&oe=utf-8

The HTTP request has four parameters

?
client=ubuntu&channel=fs&
q=404+code+error&
ie=utf-8&
oe=utf-8

This is what is contained in the browser navigation tab and what the R code needs to emulate, by sending the identical string to the server.

R and the browser are equivalent in that each sends a well-formed HTTP request to the server and receives back identical content. On the receiving end an R client and a browser are free to do with the returned content as they wish. The requests, however, must be identical.

The error message being received in your case indicates that if the same HTTP request were transmitted to the server by a browser, it would produce the same error.

The proposed solution is to make an HTTP request with a browser that produces the desired result, and from the browser bar at the time the results are served cut and paste the HTTP request in the same manner as shown above for the google query.

Parse that request as shown above, using & as the delimiter and check it against the request returned by the R variable my_url.

This is not so much an R problem as it is an HTTP syntax problem. The only difference is producing the HTTP request strings programmatically rather than manually.

1 Like