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

ee_Initialize immediately saying credentials expired #355

Open
3 tasks
coltonp2022 opened this issue Jan 4, 2024 · 25 comments
Open
3 tasks

ee_Initialize immediately saying credentials expired #355

coltonp2022 opened this issue Jan 4, 2024 · 25 comments

Comments

@coltonp2022
Copy link

  • rgee version: 1.1.7
  • R version: 4.3.2
  • Operating System: windows

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

  • You have the Python API installed (from terminal):
earthengine -h
  • You can find the credentials file on your system:
library(rgee)
ee_path <- path.expand("~/.config/earthengine/credentials")
file.exists(ee_path)
  • You can run a simple EE command from R:
library(rgee)

# Initialize the Earth Engine module.
ee_Initialize()

ee_Initialize()
── rgee 1.1.7 ───────────────────────────────────────────── earthengine-api 0.1.384 ── 
 ✔ user: coltonpadilla18@gmail.comInitializing Google Earth Engine:To authorize access needed by Earth Engine, open the following URL in a web browser and follow the instructions. If the web browser does not start automatically, please manually browse the URL below.

    https://code.earthengine.google.com/client-auth?scopes=https%3A//www.googleapis.com/auth/earthengine%20https%3A//www.googleapis.com/auth/devstorage.full_control&request_id=d9-FdixOIZE8Y3k-zPM1GzksROxL6XCc-9JxP1tQ83U&tc=ItjuDHONdNt0zjNudXLMPBN0pD0ngMCSWUND1uA3Zac&cc=F99GUvZM-uRj32GlRO7T7rtQQ5_dlO2MRm4FkyrIhg4

The authorization workflow will generate a code, which you should paste in the box below.
Enter verification code: 4/1AfJohXlyzYQXLojdF-CjVbyGpnVeL1dzTPEupjUSIWNS-wbU5yHCZS_yLwc

Successfully saved authorization token.Initializing Google Earth Engine:  DONE!
Error in value[[3L]](cond) : 
  It looks like your EE credential has expired. Try running ee_Authenticate() again or clean your credentials ee_clean_user_credentials().

Attach your Python (reticulate) configuration:

library(reticulate)
py_config()

python:         C:/Users/colto/anaconda3/envs/rgee/python.exe
libpython:      C:/Users/colto/anaconda3/envs/rgee/python38.dll
pythonhome:     C:/Users/colto/anaconda3/envs/rgee
version:        3.8.18 | packaged by conda-forge | (default, Dec 23 2023, 17:17:17) [MSC v.1929 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:/Users/colto/anaconda3/envs/rgee/Lib/site-packages/numpy
numpy_version:  1.24.4
ee:             C:\Users\colto\ANACON~1\envs\rgee\lib\site-packages\ee\__init__.p

NOTE: Python version was forced by RETICULATE_PYTHON

Description

Hi, I am trying to just get initialized into rgee and for some reason it is saying that my credentials are expired immediately after I run ee_Authenticate(). I can go and find the credentials in my machine and view them, and I can find them through R as well. It is giving me an error message:

Error in value[3L] :
It looks like your EE credential has expired. Try running ee_Authenticate() again or clean your credentials ee_clean_user_credentials().

I have ran both ee_Authenticate() and ee_clean_user_credentials() multiple times and have been unable to solve the issue. Can someone recreate this or point me in the right direction to solve it? The only issue that I can see happening is my computer is hooked up with Onedrive so I can work on both my personal and work computers from anywhere. I did have to move the credentials to match up with the path.expand() function; however, even that did not seem to solve the issue.

What I Did

── rgee 1.1.7 ───────────────────────────────────────────── earthengine-api 0.1.384 ── 
 ✔ user: coltonpadilla18@gmail.com 
 ✔ Initializing Google Earth Engine:To authorize access needed by Earth Engine, open the following URL in a web browser and follow the instructions. If the web browser does not start automatically, please manually browse the URL below.

    https://code.earthengine.google.com/client-auth?scopes=https%3A//www.googleapis.com/auth/earthengine%20https%3A//www.googleapis.com/auth/devstorage.full_control&request_id=d9-FdixOIZE8Y3k-zPM1GzksROxL6XCc-9JxP1tQ83U&tc=ItjuDHONdNt0zjNudXLMPBN0pD0ngMCSWUND1uA3Zac&cc=F99GUvZM-uRj32GlRO7T7rtQQ5_dlO2MRm4FkyrIhg4

The authorization workflow will generate a code, which you should paste in the box below.
Enter verification code: 4/1AfJohXlyzYQXLojdF-CjVbyGpnVeL1dzTPEupjUSIWNS-wbU5yHCZS_yLwc

Successfully saved authorization token.
 ✔ Initializing Google Earth Engine:  DONE!
Error in value[[3L]](cond) : 
  It looks like your EE credential has expired. Try running ee_Authenticate() again or clean your credentials ee_clean_user_credentials().
@nozimmjon
Copy link

I also bumped into the same problem...

@TianyaImpression
Copy link

I also bumped into the same problem...
image

@NicholasBerryman
Copy link

NicholasBerryman commented Jan 10, 2024

I've just run into the same issue, though notably the same credentials file appears to work fine when going directly through the Python API directly in Reticulate or Jupyter.
From that I've found a quick-and-dirty solution by just making a new python file with the following contents:

import ee

ee.Authenticate(auth_mode = 'localhost')
ee.Initialize()

Then replacing this R code:

...
rgee::ee_Initialize()
...

With

...
reticulate::py_run_file('[path to python script]')
...

@llechler
Copy link

I have the same problem.. I authenticate gee and get the message that the authentication has been successful, but as soon as I then call ee_initialize(), I get the message that I should try running ee_authenticate and so the circle begins. Has anyone found a solution to this problem yet and could help me out?

@NicholasBerryman
Copy link

NicholasBerryman commented Jan 15, 2024

@llechler
I've managed to get it working with the workaround I described just above your comment. Does that work for you? I'm happy to clarify if anything is unclear.

@llechler
Copy link

llechler commented Jan 15, 2024

Hi @NicholasBerryman, thanks for reaching out.

I just tried it by writing the python file and then calling it in R, but I get the error message in R "Error in py_run_file_impl (file, local, convert) : ModuleNotFoundError. No module named "ee".

Some more details:

py_config()
python: C:/Users/Lia/AppData/Local/r-miniconda/envs/r-reticulate/python.exe
libpython: C:/Users/Lia/AppData/Local/r-miniconda/envs/r-reticulate/python38.dll
pythonhome: C:/Users/Lia/AppData/Local/r-miniconda/envs/r-reticulate
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/Lia/AppData/Local/r-miniconda/envs/r-reticulate/Lib/site-packages/numpy
numpy_version: 1.23.4

@NicholasBerryman
Copy link

Hmm. Did you set your reticulate environment to the same one you use for rgee? If that workaround still doesn't work, we might have to wait for a more official solution.

@llechler
Copy link

I successfully managed to use both your solution and also this code snippet to initialize the GEE

reticulate::py_run_string("import ee; ee.Initialize()")
reticulate::py_run_string("print(ee.version)")
0.1.385

However, I still get the error message:
Error in value[3L] : rgee not initialized!
Please intialize rgee. See: https://r-spatial.github.io/rgee/index.html
as soon as I try to run a rgee to export a time series..
So unfortunately your workaround solution did not work for me. Unless you have an idea why, I guess I will have to wait for an "official" solution.

@cofler

This comment was marked as outdated.

1 similar comment
@cofler
Copy link

cofler commented Jan 18, 2024

The workaround doesn't fully work because it doesn't create the rgee_sessioninfo.txt file (indeed the initalization goes only through Python and rgee is created from R functions)

@andrew-caudillo
Copy link

I had this issue for quite some time. It took a lot of back and forth with google, R, and conda.

I had rgee install miniconda, even though I had conda installed. Then, I set the conda environment to that location and I have had 0 problems since. #353 (comment)

I hope this solution will help you.

@jdbcode
Copy link
Collaborator

jdbcode commented Jan 20, 2024

I think there are multiple layers of things going on here.

ee_Initialize is quite complicated - lots of checks that users are setup correctly. The error message is coming from a check on a call to get user/project assets - this appears to check that a person has a home folder for assets, and if not it tries to create one for them - this is quite outdated now that Cloud projects are the standard method for asset management.

In version 0.1.383 of the earthengine-api there were changes that make specifying cloud projects more necessary. It appears to me that in ee_Initialize the ee_check_root_folder call is not successful because a specific project is not being passed during initialization, so access is blocked and we get the [probably] wrongly attributed error message about expired credentials.

I'm not sure what the fix is for the ee_Initialize function, but people can do their own authentication and initialization just using the Earth Engine client library to bypass checks that are outdated in ee_Initialize, which is what you'd do in a Jupyter notebook, for instance.

Do this instead of ee_Initialize until it is updated:

# Import rgee.
library(rgee)

# Attempt to authenticate. If credentials are found, nothing will happen except
# a return of TRUE. If credentials are not found, it'll take you through an auth
# flow and save the credentials. If you want to force reauthentication, include
# `force=TRUE` in the call. This is generally a one-time setup step.
ee$Authenticate(auth_mode='notebook')

# Initialize - this will connect to a project. You should always call this
# before working with rgee. It is IMPORTANT THAT YOU SPECIFY A PROJECT using
# the project parameter. If you forget what project IDs you have access to, find them
# here: console.cloud.google.com/project
ee$Initialize(project='YOUR-PROJECT')  # <-- EDIT THIS FOR YOUR PROJECT

# Optionally make a request to verify you are connected.
ee$String('Hello from the Earth Engine servers!')$getInfo()

@btomairekirkland
Copy link

The workaround allows ee_Initialise() to work for me but when running rgee functions I get the error message about the rgee_sessioninfo.txt file not being found.

@csaybar
Copy link
Collaborator

csaybar commented Jan 22, 2024 via email

@jordi-1
Copy link

jordi-1 commented Jan 22, 2024

Dear Cesar,

I get that you might feel discouraged.
I would like to add that while just being a normal R user for epidemiology, I have always managed, even recently, to find ways to use rgee to access GEE data. Of course, there were times when fixing the install was longer than others but relying on an interface in a language (R) that I can understand is a major advantage.
You are mentionning multiple ways to access earthengine data, however, for a standard epidemiologist, none are as clear as rgee.
I don't think I am the only one in this situation...
Thanks again for all the help provided by your package, and please reconsider and keep it alive !!!
Long live rgee !

@TianyaImpression
Copy link

rgee is really very easy to use. R language environment + GEE is really a magic weapon for remote sensing data analysis. It is a pity to give up rgee. I hope rgee can continue to update.
Thanks again for all the help provided by your package, and please reconsider and keep it alive !!!
Long live rgee !

@Gelsleichter
Copy link

I am running in windows machine, R version 4.3.3.
Python version 3.8.18 (conda with reticulate)

It worked when I downgrade the GEE API from version 0.1.391 to 0.1.370, see details in the comment: #353 (comment)

@Cidree
Copy link

Cidree commented Mar 12, 2024

I am running in windows machine, R version 4.3.3. Python version 3.8.18 (conda with reticulate)

It worked when I downgrade the GEE API from version 0.1.391 to 0.1.370, see details in the comment: #353 (comment)

Thank you! This worked for me

@rion-saeon
Copy link

I am running in windows machine, R version 4.3.3. Python version 3.8.18 (conda with reticulate)

It worked when I downgrade the GEE API from version 0.1.391 to 0.1.370, see details in the comment: #353 (comment)

This also worked for me!

@MarShaikh
Copy link
Contributor

The workaround allows ee_Initialise() to work for me but when running rgee functions I get the error message about the rgee_sessioninfo.txt file not being found.

Sorry for referencing your comment after many months, but in case someone else gets into this problem after trying the workaround. I found a very dirty workaround to the workaround (I know, insane). Just set up your workaround as described above, and after the .py file call, write the statement rgee::ee_Initialise().

Explanation?: If I understand correctly, RGEE through python is able to do the initialization but since we are doing it through python, there is no rgee_sessioninfo.txt file generated. This file can then be generated through R's initialization command. Just a theory, but this worked for me.

@judgementc
Copy link

The workaround allows ee_Initialise() to work for me but when running rgee functions I get the error message about the rgee_sessioninfo.txt file not being found.

Sorry for referencing your comment after many months, but in case someone else gets into this problem after trying the workaround. I found a very dirty workaround to the workaround (I know, insane). Just set up your workaround as described above, and after the .py file call, write the statement rgee::ee_Initialise().

Explanation?: If I understand correctly, RGEE through python is able to do the initialization but since we are doing it through python, there is no rgee_sessioninfo.txt file generated. This file can then be generated through R's initialization command. Just a theory, but this worked for me.

Hi, your suggestion is very useful, but I can't initialize the regee with python first, so I can't generate a regee_sessioninfo.txt.
Can you please tell me how to manually create a rgee_sessioninfo.txt and put it in the right place?

@MarShaikh
Copy link
Contributor

The workaround allows ee_Initialise() to work for me but when running rgee functions I get the error message about the rgee_sessioninfo.txt file not being found.

Sorry for referencing your comment after many months, but in case someone else gets into this problem after trying the workaround. I found a very dirty workaround to the workaround (I know, insane). Just set up your workaround as described above, and after the .py file call, write the statement rgee::ee_Initialise().
Explanation?: If I understand correctly, RGEE through python is able to do the initialization but since we are doing it through python, there is no rgee_sessioninfo.txt file generated. This file can then be generated through R's initialization command. Just a theory, but this worked for me.

Hi, your suggestion is very useful, but I can't initialize the regee with python first, so I can't generate a regee_sessioninfo.txt. Can you please tell me how to manually create a rgee_sessioninfo.txt and put it in the right place?

Hi, sorry for not being clear. rgee_sessioninfo.txt is a file used by the rgee package in R. So you won't be able to generate it using Python. The only way to generate it is by using rgee::ee_Initialize() function call from your R script.

@Leprechault
Copy link

Leprechault commented May 28, 2024

For me, it doesn't work:

 reticulate::py_run_file('/home/fores/anaconda3/envs/myyolov8/GEE_auth.py')
Error in py_run_file_impl(file, local, convert) : 
  ModuleNotFoundError: No module named 'StringIO'
Run `reticulate::py_last_error()` for details.

and in my GEE_auth.pyfile I have:

import ee
import io
from io import StringIO

ee.Authenticate(auth_mode = 'localhost')
ee.Initialize()

or:

import ee

ee.Authenticate(auth_mode = 'localhost')
ee.Initialize()

@andrew-caudillo
Copy link

For me, it doesn't work:

 reticulate::py_run_file('/home/fores/anaconda3/envs/myyolov8/GEE_auth.py')
Error in py_run_file_impl(file, local, convert) : 
  ModuleNotFoundError: No module named 'StringIO'
Run `reticulate::py_last_error()` for details.

and in my GEE_auth.pyfile I have:

import ee
import io
from io import StringIO

ee.Authenticate(auth_mode = 'localhost')
ee.Initialize()

or:

import ee

ee.Authenticate(auth_mode = 'localhost')
ee.Initialize()

Have you tried just reinstalling both rgee and reticulate? Sometimes I had to do this (a few times) for the packages to work.

@janderkran
Copy link

What helped me, after going through all comments; enable earthengine API and register your project: see https://developers.google.com/earth-engine/guides/access

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