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>
(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'])

          OAUTH_SCOPE = 'https://www.googleapis.com/auth/drive'

          # 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,
                          }))
                    self.post()
                    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()
                          print(task.id)   
          
                          temp_file_prefix = _GetUniqueString()
                          email = ''
                          filename = 'test'
                          user_id = '[email protected]'

                          while task.active():
                                     logging.info('Polling for task (id: 
%s).', task.id)
                                     time.sleep(TASK_POLL_FREQUENCY)

                          def _SendMessage(message):
                                     logging.info('Sent to client: ' + 
json.dumps(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:
                                    logging.info('Task succeeded (id: 
%s).', task.id)
                                    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)

The other code is same as the example "Export to 
Drive"(https://github.com/google/earthengine-api/tree/master/demos/export-to-drive)

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.
         INFO     2018-12-25 02:41:14,302 api_server.py:275] Starting API 
server at: http://localhost:42010
         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:14,813 admin_server.py:150] Starting 
admin server at: http://localhost:8000
         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 discovery.py:270] URL being 
requested: GET 
https://www.googleapis.com/discovery/v1/apis/drive/v3/rest?userIp=124.16.186.16
         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).
         INFO     2018-12-25 02:41:40,116 discovery.py:871] URL being 
requested: GET 
https://www.googleapis.com/drive/v3/files?alt=json&q=title+contains+%221545705679SIGRWI%22
         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,235 server.py:155] Sent to client: 
{"error": "Failed to give file to user: <HttpError 400 when requesting 
https://www.googleapis.com/drive/v3/files?alt=json&q=title+contains+%221545705679SIGRWI%22
 
returned \"Invalid Value\">"}
         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!


         

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/ef6f535f-bf8a-44c1-b586-1d608bc27581%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • [google-appengine]... zi yang

Reply via email to