r-spatial / rgee

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

ee_Initialize() fails on Google server side. #273

Closed milesalanmoore closed 2 years ago

milesalanmoore commented 2 years ago

Hey friends! Hope y'all are well. I've been stumped on this issue for days now and can't find a solution. I would love to use this wonderful package but can't seem to get ee_Initialize() to successfully open an authentication window. (see image attached below). Any guidance is greatly appreciated!

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

library(rgee)

# Initialize the Earth Engine module.
ee_Initialize() #failing to Initialize...

Attach your Python (reticulate) configuration:

library(reticulate)
py_config()

python:         /Users/***/.virtualenvs/rgee/bin/python
libpython:      /Users/***/Library/r-miniconda-arm64/envs/r-reticulate/lib/libpython3.8.dylib
pythonhome:     /Users/***/.virtualenvs/rgee:/Users/***/.virtualenvs/rgee
version:        3.8.12 | packaged by conda-forge | (default, Jan 30 2022, 23:13:55)  [Clang 11.1.0 ]
numpy:          /Users/***/.virtualenvs/rgee/lib/python3.8/site-packages/numpy
numpy_version:  1.23.1
ee:             /Users/***/.virtualenvs/rgee/lib/python3.8/site-packages/ee

NOTE: Python version was forced by RETICULATE_PYTHON

Description

I followed the README instructions to get rgee up and running using rgee::ee_install(). rgee::ee_check() returns all OK. Running rgee:ee_Initialize() opens a Google window as expected but the window reads:

Screen Shot 2022-07-12 at 1 50 24 PM
Authorization Error
Error 400: invalid_request
The version of the app you're using doesn't include the latest security features to keep you protected. Please make sure to download from a trusted source and update to the latest, most secure version.

What I Did

I attempted to reinstall rgee. I triple checked ee-api is accessible in base terminal environment as well as via the ee env in conda e.g. conda activate ee. I then attempted to set up rgee manually via rgee::ee_install_set_pyenv() & `rgee::ee_install_upgrade() with no luck.

I submitted an issue to Google Earth engine as well. See feedback here: https://issuetracker.google.com/issues/238589416

ee_Initialize(drive = T)
── rgee 1.1.3 ─────────────────────────────────────────── earthengine-api 0.1.316 ── 
 ✔ user: not_defined
 ✔ Google Drive credentials:Auto-refreshing stale OAuth token.
 ✔ Google Drive credentials:  FOUND
 ✔ Initializing Google Earth Engine:

opens up the same window pictured above. running rgee::ee_install_upgrade() to roll back the earth engine api to version 0.1.302 as suggested by ee_check() does not fix the issue either.

carol-sartor commented 2 years ago

I am receiving the same error. I tried to install in more than one computer and all of them returned the same message. However, I cannot find the Python API in my computer. Any suggestions?

csaybar commented 2 years ago

Hi @carol-sartor!, which rgee version are you using? Please run as follow:

library(rgee)
reticulate::import("ee")$`__version__`

sessionInfo()
milesalanmoore commented 2 years ago

@csaybar spent some time with me in a google meeting. Updating to rgee 1.1.4 solved the Authorization error window (screenshot above in OP). However a new error occurred when running ee_Initalized.

>ee_Initialize()

── rgee 1.1.4 ──────────────────────── earthengine-api 0.1.317 ── 
 ✔ user: not_defined
 ✔ Initializing Google Earth Engine:sh: gcloud: command not found
Fetching credentials using gcloud
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  Exception: gcloud failed. Please check for any errors above and install gcloud if needed.

This new issue was likely a bit of a mess that was occurring between anaconda enviornments, miniconda, and thebase::system() command that is invoked by reticulate via the python earthengine-api's oAuth process.

Opening a terminal, typing conda deactivate to exit the base(root) env, and then running brew install --cask google-cloud-sdk made gcloud available to the root terminal. Then restarting computer, opening R, and running

library(rgee)
ee_Authenticate()
ee_Initialize() 

worked as expected. Feel free to ping Cesar or me here if anyone has any questions about our troubleshooting process.