Overview

This notebook guides you through process of testing if the Jupyter Notebook server is authorized to access the Earth Engine servers, and provides a way to authorize the server, if needed.

Testing if the Jupyter Notebook server is authorized to access Earth Engine

To begin, first verify that you can import the Earth Engine Python API package by running the following cell.


In [ ]:
import ee

Next, try to initialize the ee Python package.


In [ ]:
try:
  ee.Initialize()
  print('The Earth Engine package initialized successfully!')
except ee.EEException as e:
  print('The Earth Engine package failed to initialize!')
except:
    print("Unexpected error:", sys.exc_info()[0])
    raise

If the initialization succeeded, you can stop here. Congratulations! If not, continue on below...

Authenticating to the Earth Engine servers

If the initialization process failed, you will need to authenticate the Jupyter Notebook server so that it can communicate with the Earth Engine servers. You can initiate the authentication process by running the following command.

Note that earthengine authenticate is a system command (rather than a Python command), and the cell uses the %%bash cell magic in the first line of the cell to indicate that the cell contents should be executed using a bash shell.


In [ ]:
%%bash
earthengine authenticate --quiet

Once you have obtained an authorization code from the previous step, paste the code into the following cell and run it.


In [ ]:
%%bash
earthengine authenticate --authorization-code=PLACE_AUTH_CODE_HERE

Removing authentication credentials

Authenication credentials are stored as a file in the user's configuration directory. If you need to remove the authentication credentials, run the following cell.


In [ ]:
%%bash
rm ~/.config/earthengine