dreamrs / rte.data Goto Github PK
View Code? Open in Web Editor NEWAccess data from RTE API
License: Other
Access data from RTE API
License: Other
Bonjour,
J'ai voulu requêter digital.iservices.rte-france.com/open_api/unavailability_additional_information/v1/generation_unavailabilities mais le merge qui est dans le process data engendre une erreur.
Cordialement
Aurélien
There is an issue with token obtention because a \n
is added in base64 encoded string with jsonlite. And strangely, this is not handle by the API. This \n
addition is on purpose as explained in jeroen/jsonlite#220
Would it be possible to use base64enc
or openssl
?
# dummy ids
id_client <- "bcfe5cb5-89ac-4etb-ba60-2f83015c3e78"
id_secret <- "62ade741-453b-4d20-a812-ad1e0aad63ae"
key = list(id_client = id_client, id_secret = id_secret)
raw_string <- charToRaw(paste(key$id_client, key$id_secret, sep = ":"))
jsonlite::base64_enc(raw_string)
#> [1] "YmNmZTVjYjUtODlhYy00ZXRiLWJhNjAtMmY4MzAxNWMzZTc4OjYyYWRlNzQxLTQ1M2ItNGQy\nMC1hODEyLWFkMWUwYWFkNjNhZQ=="
base64enc::base64encode(raw_string)
#> [1] "YmNmZTVjYjUtODlhYy00ZXRiLWJhNjAtMmY4MzAxNWMzZTc4OjYyYWRlNzQxLTQ1M2ItNGQyMC1hODEyLWFkMWUwYWFkNjNhZQ=="
openssl::base64_encode(raw_string)
#> [1] "YmNmZTVjYjUtODlhYy00ZXRiLWJhNjAtMmY4MzAxNWMzZTc4OjYyYWRlNzQxLTQ1M2ItNGQyMC1hODEyLWFkMWUwYWFkNjNhZQ=="
Created on 2019-06-13 by the reprex package (v0.3.0.9000)
key = list(id_client = id_client, id_secret = id_secret)
rte.data::get_token(key)
#> Error: Bad Request (HTTP 400)
get_token2 <- function(key, user = NULL, proxy_pwd = NULL) {
if (is.list(key))
key <- base64enc::base64encode(charToRaw(paste(key$id_client, key$id_secret, sep = ":")))
cli <- crul::HttpClient$new(
url = rte.data:::get_url("url.auth"),
headers = list(
Authorization = paste("Basic", key)
)
)
res <- try(cli$post(), silent = TRUE)
if ("try-error" %in% class(res))
stop(proxy_error(getOption("rte.data.url.base")))
res$raise_for_status()
txt <- res$parse("UTF-8")
json <- jsonlite::fromJSON(txt)
json
}
res <- get_token2(key)
names(res)
#> [1] "access_token" "token_type" "expires_in"
Created on 2019-06-13 by the reprex package (v0.3.0.9000)
Why the choice of storing a token by api name ?
With data.rte-france.com, you can create an application that can register several api ressource and with the same id client and secret (so same token), you can retrieve several ressource.
Currently, if I use set_key
and I need to register once for get_consumption
, and once for get_physical_flows
. However, I register the two ressource in the same app, so one token can get me both.
Does your package suppose that one resource is register in one application ?
I think a mechanism closer to the one in httr with a logic of registering an application to get access to some resources can help avoid duplication in options or environment variables.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.