GEE python:“ee.batch.Export.image.toAsset” "Request had insufficient authentication scopes."

558 Views Asked by At

I am getting an error when using python GEE api to save processed image in Colab. The code and the error are as follow:

# Load a landsat image and select three bands.
landsat = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_123032_20140515')\
            .select(['B4', 'B3', 'B2'])

# Create a geometry representing an export region.
geometry = ee.Geometry.Rectangle([116.2621, 39.8412, 116.4849, 40.01236])
center = geometry.centroid().getInfo()['coordinates']
center.reverse()

Mapdisplay(center,{'landsat':landsat.getMapId()},zoom_start=7)
# Get band 4 from the Landsat image, copy it.
band4 = landsat.select('B4').rename('b4_mean')\
               .addBands(landsat.select('B4').rename('b4_sample'))\
               .addBands(landsat.select('B4').rename('b4_max'))\

# Export the image to an Earth Engine asset.
task = ee.batch.Export.image.toAsset(**{
  'image': band4,
  'description': 'imageToAssetExample',
  'assetId': 'users/csaybar/exampleExport',
  'scale': 100,
  'region': geometry.getInfo()['coordinates']
})

task.start()

This error occurs due to "task.start()"

WARNING:googleapiclient.http:Invalid JSON content from response: b'{\n  "error": {\n    "code": 403,\n    "message": "Request had insufficient authentication scopes.",\n    "status": "PERMISSION_DENIED",\n    "details": [\n      {\n        "@type": "type.googleapis.com/google.rpc.ErrorInfo",\n        "reason": "ACCESS_TOKEN_SCOPE_INSUFFICIENT",\n        "domain": "googleapis.com",\n        "metadata": {\n          "method": "google.earthengine.v1alpha.EarthEngine.ExportImage",\n          "service": "earthengine.googleapis.com"\n        }\n      }\n    ]\n  }\n}\n'
---------------------------------------------------------------------------
HttpError                                 Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/ee/data.py in _execute_cloud_call(call, num_retries)
    327   try:
--> 328     return call.execute(num_retries=num_retries)
    329   except googleapiclient.errors.HttpError as e:

6 frames
HttpError: <HttpError 403 when requesting https://earthengine.googleapis.com/v1alpha/projects/earthengine-legacy/image:export?alt=json returned "Request had insufficient authentication scopes.". Details: "[{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'ACCESS_TOKEN_SCOPE_INSUFFICIENT', 'domain': 'googleapis.com', 'metadata': {'method': 'google.earthengine.v1alpha.EarthEngine.ExportImage', 'service': 'earthengine.googleapis.com'}}]">

During handling of the above exception, another exception occurred:

EEException                               Traceback (most recent call last)
/usr/local/lib/python3.8/dist-packages/ee/data.py in _execute_cloud_call(call, num_retries)
    328     return call.execute(num_retries=num_retries)
    329   except googleapiclient.errors.HttpError as e:
--> 330     raise _translate_cloud_exception(e)
    331 
    332 

EEException: Request had insufficient authentication scopes.

I tried to look for a GEE service in the google cloud console to enable it, but couldn't find one. And I want to konw how to fix this problem.

1

There are 1 best solutions below

0
On BEST ANSWER

The most recent version of the google earth engine API seems to have introduced some issues with gcloud. Try rolling back to an earlier version using conda install -c conda-forge earthengine-api=0.1.320 and then rerunning your process.

For future reference, most GEE-related questions get asked and answered over at gis.stackexchange.com.