Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_dataset_ibamam: Error in open.connection(con, "rb"): SSL certificate problem: self signed certificate in #20

Open
MatthieuStigler opened this issue Jun 29, 2022 · 1 comment

Comments

@MatthieuStigler
Copy link

Thanks for this package!!

Trying to use get_dataset_ibamam, I get error: Error in open.connection(con, "rb"): SSL certificate problem: self signed certificate in certificate chain. This seems to be suffering form the same issue that datazoom.amazonia is facing: datazoompuc/datazoom.amazonia#107

Unfortunately, the temporary workaround there to use options(download.file.method="curl", download.file.extra="-k -L") won't work, as get_dataset_ibamam() is using directly jsonlite::fromJSON?

Thanks!

library(Ibamam)
fines_applied_Para <- get_dataset_ibamam(dataset = "distribuidas", uf = "PA")
#> Error in open.connection(con, "rb"): SSL certificate problem: self signed certificate in certificate chain

## internal code:
texto_link <- "Arrecadacao/arrecadacaobenstutelados"
uf <- "PA"
jsonlite::fromJSON(paste0("http://dadosabertos.ibama.gov.br/dados/SICAFI/", 
                          uf, "/", texto_link, ".json"))
#> Error in open.connection(con, "rb"): SSL certificate problem: self signed certificate in certificate chain

## raw code:
tm <- tempfile()
download.file(paste0("http://dadosabertos.ibama.gov.br/dados/SICAFI/", 
                     uf, "/", texto_link, ".json"),
              destfile = tm)
#> Warning in download.file(paste0("http://dadosabertos.ibama.gov.br/dados/
#> SICAFI/", : URL 'https://dadosabertos.ibama.gov.br/dados/SICAFI/PA/Arrecadacao/
#> arrecadacaobenstutelados.json': status was 'SSL peer certificate or SSH remote
#> key was not OK'
#> Error in download.file(paste0("http://dadosabertos.ibama.gov.br/dados/SICAFI/", : cannot open URL 'http://dadosabertos.ibama.gov.br/dados/SICAFI/PA/Arrecadacao/arrecadacaobenstutelados.json'

## workaround
options(download.file.method="curl", download.file.extra="-k -L")

download.file(paste0("http://dadosabertos.ibama.gov.br/dados/SICAFI/", 
                     uf, "/", texto_link, ".json"),
              destfile = tm)

Created on 2022-06-29 by the reprex package (v2.0.1)

@MatthieuStigler
Copy link
Author

Temporary workaround if someone is interested...

library(Ibamam)
fines_applied_Para <- get_dataset_ibamam(dataset = "distribuidas", uf = "PA")
#> Error in open.connection(con, "rb"): SSL certificate problem: self signed certificate in certificate chain

get_data_of_state_me <- function (uf, tipo_multa)  {
  if (tipo_multa == "arrecadadas") {
    texto_link <- "Arrecadacao/arrecadacaobenstutelados"
  }
  else if (tipo_multa == "distribuidas") {
    texto_link <- "Quantidade/multasDistribuidasBensTutelados"
  }
  else {
    stop("The argument 'tipo_multa' can receive one of the values:\n         'arrecadadas' or 'distribuidas'")
  }
  tmp <- tempfile()
  download.file(paste0("http://dadosabertos.ibama.gov.br/dados/SICAFI/", 
                       uf, "/", texto_link, ".json"),
                destfile = tmp)
  dataset <- jsonlite::fromJSON(tmp)
  dplyr::as_tibble(dataset$data)
}

options(download.file.method="curl", download.file.extra="-k -L")
assignInNamespace("get_data_of_state", get_data_of_state_me, "Ibamam")
fines_applied_Para <- get_dataset_ibamam(dataset = "distribuidas", uf = "PA")

Created on 2022-06-29 by the reprex package (v2.0.1)

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

No branches or pull requests

1 participant