cloudyr/googleComputeEngineR

Error: gce_auth() is defunct.

Closed this issue · 16 comments

Dear Mark,

I am struggling to solve the following error:

Error: gce_auth() is defunct. Authenticate instead by downloading your JSON key and placing in a GCE_AUTH_FILE environment argument. See https://cloudyr.github.io/googleComputeEngineR/articles/installation-and-authentication.html or vignette('installation-and-authentication', package = 'googleComputeEngineR')

I am fairly new to Rstudio so the issue might only be a minor fix. I fllowed this li you created https://code.markedmondson.me/launch-rstudio-server-google-cloud-in-two-lines-r/.
However, whether or not I set my variables in my .Renviron file, or use Sys.setenv() method, the same error occurs.
Might be the auth file path? I downloaded the json key file which I saved in my project directory.

`library(googleComputeEngineR)
project <- "myProjectID"
zone <- "us-east1-c"
account_key <- "*.json"

Sys.setenv(GCE_AUTH_FILE = account_key,
GCE_DEFAULT_PROJECT_ID = project,
GCE_DEFAULT_ZONE = zone)

gce_auth()`

Session info:
`R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_South Africa.1252 LC_CTYPE=English_South Africa.1252
[3] LC_MONETARY=English_South Africa.1252 LC_NUMERIC=C
[5] LC_TIME=English_South Africa.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] usethis_1.5.0 googleComputeEngineR_0.3.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.0 codetools_0.2-15 listenv_0.7.0 future_1.13.0 digest_0.6.19
[6] assertthat_0.2.0 R6_2.3.0 jsonlite_1.6 neuralnet_1.44.2 httr_1.4.0
[11] rlang_0.3.1 curl_3.3 fs_1.3.1 googleAuthR_0.7.0 tools_3.5.2
[16] glue_1.3.0 parallel_3.5.2 compiler_3.5.2 askpass_1.1 globals_0.12.4
[21] memoise_1.1.0 openssl_1.4`

Would much appreciate your help!

Result in Rstudio console window after execution:

`> library(googleComputeEngineR)
Successfully authenticated via rrkey.json
Set default project ID to 'r-program-xxxxxx'
Set default zone to 'us-east1-c'
Warning message:
package ‘googleComputeEngineR’ was built under R version 3.5.3

gce_auth()
Error: gce_auth() is defunct. Authenticate instead by downloading your JSON key and placing in a GCE_AUTH_FILE environment argument. See https://cloudyr.github.io/googleComputeEngineR/articles/installation-and-authentication.html or vignette('installation-and-authentication', package = 'googleComputeEngineR')`

Therefore, the json key is found and successfully authenticated. Don't understand why the error still occurs?

Once authenticated, you do not need to use gce_auth() at all. Just move on to listing and creating VMs.

Thank you!

Is it possible to use multiple GPUs when creating a live instance following the link you created? (https://code.markedmondson.me/launch-rstudio-server-google-cloud-in-two-lines-r/)

Can't seem to fix this error " Instances with guest accelerators do not support live migration. "when using an accelerator_count and acceleratorType in my gce_vm() method?

Thanks in advance!

You have to change the scheduling option for GPUs, but please see this documentation on the website for the GPU support for more details https://cloudyr.github.io/googleComputeEngineR/articles/gpu.html

Hi

I get the following error:

Error: gce_auth() is defunct. Authenticate instead by downloading your JSON key and placing in a GCE_AUTH_FILE environment argument. See https://cloudyr.github.io/googleComputeEngineR/articles/installation-and-authentication.html or vignette('installation-and-authentication', package = 'googleComputeEngineR')

This is the setup:

library(googleComputeEngineR)

#setup--------------------------------------------
project <- "programmads-gcp"
zone <- "europe-west1-b"
account_key <- "gcs-key.json"

Sys.setenv(GCE_AUTH_FILE = account_key,

  •        GCE_DEFAULT_PROJECT_ID = project,
    
  •        GCE_DEFAULT_ZONE = zone)
    

gce_auth()

I am not authenticated because I get this:

default_project <- gce_get_project("programmads-gcp")
2019-07-03 11:13:01> No authorization yet in this session!
2019-07-03 11:13:01> No .httr-oauth file exists in current working directory. Do library authentication steps to provide credentials.
Error: Invalid token

after having run this:

default_project <- gce_get_project("programmads-gcp")
default_project$name

Thank you.

You need to set the environment arguments before you load the library, and then never use gce_auth(). The environment arguments are best set in an .Renviron file rather than in code using Sys.setenv()

e.g.

Sys.setenv("GCE_AUTH_FILE"="your-key.json") # but better to set in an .Renviron file
library(googleComputeEngineR)
gce_get_project("your-project")

Hi @MarkEdmondson1234 and @hendrikds ,

I am also having the exact same issue. I receive the error,

Setting scopes to https://www.googleapis.com/auth/cloud-platform Failed! Auto-authentication via GCE_AUTH_FILE=key_cloud_engine.json - error was: GCE_AUTH_FILE specified in environment variables but file not found - looked for key_cloud_engine.json and called from C:/Users/admin/Desktop/R/app/twitter Set default project ID to 'crypto-302314' Set default zone to 'europe-west1-b

My R code is the following.

`project <- "crypto-302314"
zone <- "europe-west1-b"
account_key <- "key_cloud_engine.json"

Sys.setenv(GCE_AUTH_FILE = account_key,
GCE_DEFAULT_PROJECT_ID = project,
GCE_DEFAULT_ZONE = zone)

library(googleComputeEngineR)

gce_get_project("crypto-302314")`

I have also attempted to create an .Renviron file in text file format which is located in the home directory folder.

The code I used is below.

GCE_AUTH_FILE = "/Users/admin/Desktop/R/app/twitter/key_cloud_engine.json" GCE_DEFAULT_PROJECT_ID = "crypto-302314" GCE_DEFAULT_ZONE = "europe-west1-b"
However, when I load the package first and run gce_get_project("crypto-302314") it is not being automatically authenticated and get this error below.

2021-01-21 19:34:09 > No authorization yet in this session! i 2021-01-21 19:34:09 > No .httr-oauth file exists in current working directory. Do library authentication steps to provide credentials. Error: Invalid token

I'm not sure what the problem is. Can you see what might be causing the problem? As the problem is the same as yours, @hendrikds I was wondering if you managed to resolve it?

Thanks very much in advance.
Jem

The authentication file is not being found. I'm not sure if you are on Windows or Mac or something else as you're using both in the code above ("/Users/admin/Desktop/R/app/twitter/key_cloud_engine.json") and ("C:/Users/admin/Desktop/R/app/twitter"

You can verify if the file is seen using file.exists(Sys.getenv("GCE_AUTH_FILE")) which should say TRUE before you run any more functions.

Hi @MarkEdmondson1234 ,

Thank you very much for the quick response. Yes, thanks for spotting that. I have fixed it accordingly now on the .Renviron file to C:/Users/admin/Desktop/R/app/twitter/key_cloud_engine.json. I have re run with Renviron file but still receive the error below. I am using Windows. After running file.exists(Sys.getenv("GCE_AUTH_FILE")), i receive a response "FALSE". Taking it that it is not locating the json file. I just included the R session info below.

Setting scopes to https://www.googleapis.com/auth/cloud-platform Failed! Auto-authentication via GCE_AUTH_FILE=key_cloud_engine.json - error was: GCE_AUTH_FILE specified in environment variables but file not found - looked for key_cloud_engine.json and called from C:/Users/admin/Desktop/R/app/twitter Set default project ID to 'crypto-302314' Set default zone to 'europe-west1-b'

Here below is the session info.

`R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_Ireland.1252 LC_CTYPE=English_Ireland.1252 LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C
[5] LC_TIME=English_Ireland.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] googleComputeEngineR_0.3.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 googleAuthR_1.3.1 compiler_4.0.3 later_1.1.0.1 prettyunits_1.1.1 remotes_2.2.0 tools_4.0.3
[8] testthat_3.0.1 digest_0.6.27 pkgbuild_1.2.0 pkgload_1.1.0 jsonlite_1.7.2 gargle_0.5.0 lifecycle_0.2.0
[15] memoise_1.1.0 rlang_0.4.9 shiny_1.5.0 cli_2.2.0 rstudioapi_0.13 parallel_4.0.3 xfun_0.19
[22] fastmap_1.0.1 httr_1.4.2 withr_2.3.0 globals_0.14.0 fs_1.5.0 desc_1.2.0 devtools_2.3.2
[29] rprojroot_2.0.2 glue_1.4.2 listenv_0.8.0 R6_2.5.0 processx_3.4.5 parallelly_1.23.0 fansi_0.4.1
[36] sessioninfo_1.1.1 purrr_0.3.4 callr_3.5.1 magrittr_2.0.1 codetools_0.2-16 usethis_2.0.0 promises_1.1.1
[43] ps_1.5.0 ellipsis_0.3.1 htmltools_0.5.0 shinythemes_1.1.2 assertthat_0.2.1 future_1.21.0 mime_0.9
[50] xtable_1.8-4 httpuv_1.5.4 tinytex_0.28 crayon_1.3.4 `

The error message has some useful info to help debug here: "looked for key_cloud_engine.json and called from C:/Users/admin/Desktop/R/app/twitter"

Which means its looking here: C:/Users/admin/Desktop/R/app/twitter/key_cloud_engine.json

Either move it to there or updated the code to use absolute file paths rather than relative, as that's usually safest.

I have updated the code to try absolute file paths like mentioned here. However, the error still persists.

`project <- "crypto-302314"
zone <- "europe-west1-b"
account_key <- "C:/Users/admin/Desktop/R/app/twitter/key_cloud_engine.json"

Sys.setenv(GCE_AUTH_FILE = account_key,
GCE_DEFAULT_PROJECT_ID = project,
GCE_DEFAULT_ZONE = zone)

library(googleComputeEngineR)

file.exists(Sys.getenv("GCE_AUTH_FILE"))`

Error received.
`Setting scopes to https://www.googleapis.com/auth/cloud-platform
Failed! Auto-authentication via GCE_AUTH_FILE=C:/Users/admin/Desktop/R/app/twitter/key_cloud_engine.json - error was: GCE_AUTH_FILE specified in environment variables but file not found -
looked for C:/Users/admin/Desktop/R/app/twitter/key_cloud_engine.json and called from C:/Users/admin/Documents
Set default project ID to 'crypto-302314'
Set default zone to 'europe-west1-b'

file.exists(Sys.getenv("GCE_AUTH_FILE"))
[1] FALSE`

Hi @MarkEdmondson1234 ,

Thanks for your help! It has worked. I've realized the problem and the error I was making. I renamed the file .JSON at the end to convert the key file as I did not originally have a JSON reader. And if I remember correctly, I did that as it was in a different file format at first. So basically, it should have read in R "key_cloud_engine.json.json". Sorry rookie mistake! Thanks again though for your help!!

Hi Mark,
I get the following error on running gcs_get_project(). The default project and zone was set from the .Renviron file.

Request Status Code: 404
Error: API returned: The resource 'projects/my-rstudio-project' was not found

Does this mean that I do not have permission to launch a VM?

It looks like you are calling a GCP project you don't have, the default example from the docs.