Initializing an earth engine project in Colab

Question:

I can no longer initailize my own earth engine project on Google colab using Python.

I tried initializing using the ee.Initialize() method on Colab with used to provide with a link that will generate a token to my project but instead i get this error:

WARNING:googleapiclient.http:Encountered 403 Forbidden with reason "PERMISSION_DENIED"
---------------------------------------------------------------------------
HttpError                                 Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/ee/data.py in _execute_cloud_call(call, num_retries)
    382   try:
--> 383     return call.execute(num_retries=num_retries)
    384   except googleapiclient.errors.HttpError as e:

7 frames
HttpError: <HttpError 403 when requesting https://earthengine.googleapis.com/v1/projects/earthengine-legacy/algorithms?prettyPrint=false&alt=json returned "Google Earth Engine API has not been used in project 522309567947 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/earthengine.googleapis.com/overview?project=522309567947 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.". Details: "[{'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Google developers console API activation', 'url': 'https://console.developers.google.com/apis/api/earthengine.googleapis.com/overview?project=522309567947'}]}, {'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'SERVICE_DISABLED', 'domain': 'googleapis.com', 'metadata': {'service': 'earthengine.googleapis.com', 'consumer': 'projects/522309567947'}}]">

During handling of the above exception, another exception occurred:

EEException                               Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/ee/data.py in _execute_cloud_call(call, num_retries)
    383     return call.execute(num_retries=num_retries)
    384   except googleapiclient.errors.HttpError as e:
--> 385     raise _translate_cloud_exception(e)  # pylint: disable=raise-missing-from
    386 
    387 

EEException: Google Earth Engine API has not been used in project 522309567947 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/earthengine.googleapis.com/overview?project=522309567947 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry

.

Asked By: MohaFox

||

Answers:

Their lack of documentation on this change is incredibly frustrating, but fortunately it’s a very easy fix (or at least it was for me).

If you go to your earth engine code editor and click on the ‘Assets’ tab, then copy the name of the Project that all of your EE assets are that you’re trying to access.see linked image here:

Then, at the initialization step in your colab script, you replace ‘ee.Initialize()’ with ‘ee.Initiliaze(project=’NameofYourEarthEngineProject’)

Hope this helps.

Answered By: elevenson

There is also a solution offered here

It involves going into your Google Cloud account and explicitely activating the GEE api, then creating a new project which you end up specifying when calling ee.Initialize(). The benefit of this is that when you call GEE from Colab, you no longer get that convoluted series of clicks and links to get a token, it just runs and activates. Frustrating at first but in the long term, it’s a time saver.

Answered By: Patrice Carbonneau