google / earthengine-community

Tutorials and content created by Earth Engine users, for Earth Engine users
https://earthengine.google.com/
Apache License 2.0
574 stars 742 forks source link

Can no longer authenticate #762

Closed haydenclose closed 9 months ago

haydenclose commented 9 months ago

Been using Colab over the last year and using the following code to access image catalogues. I am running this off my personal google account and not sure what is going on?

# Trigger the authentication flow
ee.Authenticate()

# Initialize the library
ee.Initialize()

However, recently i keep getting the error below 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) 378 try: --> 379 return call.execute(num_retries=num_retries) 380 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': {'consumer': 'projects/522309567947', 'service': 'earthengine.googleapis.com'}}]">

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) 379 return call.execute(num_retries=num_retries) 380 except googleapiclient.errors.HttpError as e: --> 381 raise _translate_cloud_exception(e) # pylint: disable=raise-missing-from 382 383

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.

jdbcode commented 9 months ago

earthengine-api v0.1.383 include changes for authentication and initialization (see changelog and updated guide).

You'll probably need to add the project you'd like to initialize with, e.g.:

ee.Initialize(project='my-project-id')

Can you please confirm whether this works for you or not.

haydenclose commented 9 months ago

Thanks for the reply but still somewhat confused. So for colab examples now i need to create a project for each one? even if it is a demo script or examples from github https://colab.research.google.com/github/google/earthengine-community/blob/master/tutorials/detecting-changes-in-sentinel-1-imagery-pt-1/index.ipynb#scrollTo=XeFsiSp2aDL6? I created a project and tried it again but still having issues

ee.Authenticate()
ee.Initialize(project = 'Cloud Based Oil Detection')

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 400 when requesting https://earthengine.googleapis.com/v1/projects/Cloud%20Based%20Oil%20Detection/algorithms?prettyPrint=false&alt=json returned "Project 'projects/Cloud Based Oil Detection' not found or deleted.". Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'USER_PROJECT_DENIED', 'domain': 'googleapis.com', 'metadata': {'service': 'earthengine.googleapis.com', 'consumer': 'projects/Cloud Based Oil Detection'}}]">

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: Project 'projects/Cloud Based Oil Detection' not found or deleted.

jdbcode commented 9 months ago

Earth Engine computation is run through a Cloud project. You only need a single Cloud project that is Earth Engine enabled. For example, my primary project ID is 'ee-braaten'. I use it in the JavaScript Code Editor and in any Colab notebook that I'm using Earth Engine. No need for a separate project for each Notebook - it is a one-time setup.

It looks like you are providing the Project name, but it needs to be the Project ID. See the distinction here: https://cloud.google.com/resource-manager/docs/creating-managing-projects

jdbcode commented 9 months ago

Closing this thread as it is off-topic (not related to contents of the repository). For help with general Earth Engine errors, please see this help guide for routing the issue.

In this case, a good resource is the Earth Engine Developer Forum. There is a current thread on the auth issue, for example.