Trying to access an API with httr
on macOS produces a certificate error.
httr::GET("https://unstats.un.org/SDGAPI/v1/sdg/Indicator/List")
#> Error in curl::curl_fetch_memory(url, handle = handle): SSL certificate problem: certificate has expired
However, running this on multiple Windows machines is successful, with no additional setup other than installing httr
and running the above code (it shouldn't need a certificate). Is it something server-side that is preventing access for some reason or something client-side that I can adjust? I was unable to find anything online about general certificate issues with httr
and macOS.
I can successfully access other APIs on this machine using httr
, so it leads me to believe this is a server-side issue, but don't have enough experience or knowledge to fully troubleshoot this on my own.
Below is my session info for reference. Thanks for any help you can provide.
Session info:
#> R version 4.0.0 (2020-04-24)
#> Platform: x86_64-apple-darwin19.4.0 (64-bit)
#> Running under: macOS Catalina 10.15.4
#>
#> Matrix products: default
#> BLAS/LAPACK: /usr/local/Cellar/openblas/0.3.9/lib/libopenblasp-r0.3.9.dylib
#>
#> locale:
#> [1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] Rcpp_1.0.4.6 digest_0.6.25 R6_2.4.1 magrittr_1.5
#> [5] evaluate_0.14 highr_0.8 httr_1.4.1 rlang_0.4.6
#> [9] stringi_1.4.6 curl_4.3 rmarkdown_2.1 tools_4.0.0
#> [13] stringr_1.4.0 xfun_0.14 yaml_2.2.1 compiler_4.0.0
#> [17] htmltools_0.4.0 knitr_1.28
I have the exact same problem since yesterday. After looking things up, turns out a common root CA certificate expired on 30th May (see this answer). In general, what solved my error is to force Curl
(which supports httr
functions) to ignore the certificate:
set_config(config(ssl_verifypeer = FALSE))
options(RCurlOptions = list(ssl_verifypeer = FALSE))
options(rsconnect.check.certificate = FALSE)
I knows close to nothing about server issues. But this works for me, so I hope it does for you too!