I want to deploy the APP Engine apps with Earth Engine, and I made all contents following the steps of
web(
https://developers.google.com/earth-engine/app_engine_intro#deploying-app-engine-apps-with-earth-engine).
The 'oauth2client.client.SignedJwtAssertionCredentials' function in the example "Export to Drive" has been removed, and I replace it by 'oauth2client.service_account.ServiceAccountCredentials.from_json_keyfile_name'.
I only want to upload my task to my project, and export it to my drive, so I delete needless code.
The main code of my server.py as follow:
EE_CREDENTIALS = ee.ServiceAccountCredentials(
config.EE_ACCOUNT, config.EE_PRIVATE_KEY_FILE)
try:
ee.Initialize(EE_CREDENTIALS)
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
JINJA2_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
autoescape=True,
extensions=['jinja2.ext.autoescape'])
# The app's service account credentials (for Google Drive).
APP_CREDENTIALS = oauth2client.service_account.ServiceAccountCredentials.from_json_keyfile_name(
config.EE_PRIVATE_KEY_FILE,
OAUTH_SCOPE)
APP_DRIVE_HELPER = drive.DriveHelper(APP_CREDENTIALS)
# The decorator to trigger the user's Drive permissions request flow.
OAUTH_DECORATOR = oauth2client.contrib.appengine.OAuth2Decorator(
client_id=config.OAUTH_CLIENT_ID,
client_secret=config.OAUTH_CLIENT_SECRET,
scope=OAUTH_SCOPE)
client_id='104509043647545372991'
class MainPage(webapp2.RequestHandler):
def get(self):
template = JINJA2_ENVIRONMENT.get_template('index_test.html')
self.response.out.write(template.render({
'channelToken': channel.create_channel(client_id),
'clientId': client_id,
}))
def post(self):
def NDVI(image):
task = ee.batch.Export.image.toDrive(
image=ndvi_collection.max(),
description='NDVI',
region=region.getInfo()["coordinates"],
scale=30,
crs="EPSG:4326")
task.start()
temp_file_prefix = _GetUniqueString()
email = ''
filename = 'test'
while task.active():
time.sleep(TASK_POLL_FREQUENCY)
def _SendMessage(message):
_SendMessageToClient(client_id, filename, message)
# Make a copy (or copies) in the user's Drive if the task succeeded.
state = task.status()['state']
if state == ee.batch.Task.State.COMPLETED:
try:
link = _GiveFilesToUser(temp_file_prefix, email, user_id, filename)
# Notify the user's browser that the export is complete.
_SendMessage({'link': link})
except Exception as e: # pylint: disable=broad-except
_SendMessage({'error': 'Failed to give file to user: ' + str(e)})
else:
_SendMessage({'error': 'Task failed (id: %s).' %
task.id})
app = webapp2.WSGIApplication([
('/', MainPage),
(OAUTH_DECORATOR.callback_path, OAUTH_DECORATOR.callback_handler()),
], debug=True)
I use the dev_appserver.py to run the app, it returns this error:
root@localhost:/home/ftp/global_change/site-py# dev_appserver.py --host 0.0.0.0 --enable_host_checking false app.yaml
INFO 2018-12-25 02:41:14,161 devappserver2.py:278] Skipping SDK update check.
WARNING 2018-12-25 02:41:14,757 inotify_file_watcher.py:203] There are too many directories in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
INFO 2018-12-25 02:41:14,812 dispatcher.py:256] Starting module "default" running at:
http://0.0.0.0:8080 INFO 2018-12-25 02:41:16,841 instance.py:294] Instance PID: 30984
INFO 2018-12-25 02:41:17,715 client.py:614] Attempting refresh to obtain initial access_token
INFO 2018-12-25 02:41:17,750 client.py:903] Refreshing access_token
The Earth Engine package initialized successfully!
INFO 2018-12-25 02:41:18,302 client.py:614] Attempting refresh to obtain initial access_token
INFO 2018-12-25 02:41:18,335 client.py:903] Refreshing access_token
ISMM6BOPPJUQZME5KXJCVVM2
INFO 2018-12-25 02:41:19,546 server.py:151] Polling for task (id: ISMM6BOPPJUQZME5KXJCVVM2).
INFO 2018-12-25 02:41:29,727 server.py:151] Polling for task (id: ISMM6BOPPJUQZME5KXJCVVM2).
INFO 2018-12-25 02:41:40,105 server.py:161] Task succeeded (id: ISMM6BOPPJUQZME5KXJCVVM2).
WARNING 2018-12-25 02:41:40,119 urlfetch_stub.py:575] Stripped prohibited headers from URLFetch request: ['content-length']
INFO 2018-12-25 02:41:40,258 module.py:861] default: "GET / HTTP/1.1" 200 1020
INFO 2018-12-25 02:41:40,561 module.py:861] default: "GET /jqueryui/style.css HTTP/1.1" 404 154
INFO 2018-12-25 02:41:40,806 module.py:861] default: "GET /static/ee_api_js.js HTTP/1.1" 304 -
INFO 2018-12-25 02:41:40,808 module.py:861] default: "GET /static/jquery.min.js HTTP/1.1" 304 -
INFO 2018-12-25 02:41:40,810 module.py:861] default: "GET /static/script.js HTTP/1.1" 304 -
I google this error, someone thinks it is the problem of authentication, and someone considers that the server_account may be wrong. But I have no idea to solve it.
My service account had been whitelisted for Earth Engine access in May.
I hope I can get some help from you!
Thank you!