r-spatial / rgee

Google Earth Engine for R
https://r-spatial.github.io/rgee/
Other
677 stars 146 forks source link

ee_Initialize() error 'invalid_grant' #278

Closed CourtneyMarne closed 2 years ago

CourtneyMarne commented 2 years ago

At submit an issue, please attached the following information of your rgee session:

Attach your Python (reticulate) configuration:

library(reticulate)
py_config()
python:         C:/Users/court/AppData/Local/r-miniconda/envs/rgee/python.exe
libpython:      C:/Users/court/AppData/Local/r-miniconda/envs/rgee/python38.dll
pythonhome:     C:/Users/court/AppData/Local/r-miniconda/envs/rgee
version:        3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 05:59:00) [MSC v.1929 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/court/AppData/Local/r-miniconda/envs/rgee/Lib/site-packages/numpy
numpy_version:  1.23.1
ee:             C:\Users\court\AppData\Local\R-MINI~1\envs\rgee\lib\site-packages\ee\__init__.p

Description

I have been using rgee for ages but today it it suddenly giving me this error upon ee_initialize() and I can't figure out what the problem is...

What I Did

library(rgee)
ee_Initialize()
-- rgee 1.1.4 ----------------------------------------------- earthengine-api 0.1.317 -- 
 v user: not_defined
 v Initializing Google Earth Engine:
 Error in py_call_impl(callable, dots$args, dots$keywords) : 
google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})

3.
stop(structure(list(message = "google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})\n", 
call = py_call_impl(callable, dots$args, dots$keywords), 
cppstack = NULL), class = c("Rcpp::exception", "C++Error", 
"error", "condition")))
2.
ee$Initialize(credentials = credentials, opt_url = opt_url, cloud_api_key = cloud_api_key, 
http_transport = http_transport, project = project)
1.
ee_Initialize()
CourtneyMarne commented 2 years ago

UPDATE: trying again this morning and now it says

library(rgee)
ee_Initialize(user='cmarnew')
-- rgee 1.1.4 -------------------------------------------------------------------------------------- earthengine-api 0.1.317 -- 
 v user: cmarnew 
 v Initializing Google Earth Engine:Error in py_call_impl(callable, dots$args, dots$keywords) : 
  google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})
CourtneyMarne commented 2 years ago

I have resolved the issue and leave the solution here to help anyone else:

I opened the anaconda promt (anaconda3) and installed/updated gcloud

pip install google-cloud
gcloud components update

when using ee_Initialize() I also used my personal user ID instead of my work user and it now is working

driadash commented 1 year ago

Hello! I have a similar problem on mac but cannot fix it. Can you please help me?

> ee_Initialize() ── rgee 1.1.5 ───────────────────────────────────────────────────────── earthengine-api 0.1.323 ── ✔ user: not_defined ✔ Initializing Google Earth Engine:Error in py_call_impl(callable, call_args$unnamed, call_args$named) : google.auth.exceptions.RefreshError: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'}) Runreticulate::py_last_error()for details.

> py_config() python: /Users/admin/.virtualenvs/rgee/bin/python libpython: /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/config-3.11-darwin/libpython3.11.dylib pythonhome: /Users/admin/.virtualenvs/rgee:/Users/admin/.virtualenvs/rgee version: 3.11.5 (v3.11.5:cce6ba91b3, Aug 24 2023, 10:50:31) [Clang 13.0.0 (clang-1300.0.29.30)] numpy: /Users/admin/.virtualenvs/rgee/lib/python3.11/site-packages/numpy numpy_version: 1.26.0 ee: /Users/admin/.virtualenvs/rgee/lib/python3.11/site-packages/ee