Appcfg.py shows that you should be logged in as administrator

When I try to load csv sample data into my GAE application using appcfg.py , it shows an error below 401.

 2015-11-04 10:44:41,820 INFO client.py:571 Refreshing due to a 401 (attempt 2/2) 2015-11-04 10:44:41,821 INFO client.py:797 Refreshing access_token Error 401: --- begin server output --- You must be logged in as an administrator to access this. --- end server output --- 

Here is the command I tried,

 appcfg.py upload_data --application=dev~app --url=http://localhost:8080/_ah/remote_api --filename=data/sample.csv 
+8
python google-app-engine
source share
5 answers

Here's how we do it to use custom authentication.

Custom handler in app.yaml

 - url: /remoteapi.* script: remote_api.app 

Wsgi user application in remote_api.py to override CheckIsAdmin

 from google.appengine.ext.remote_api import handler from google.appengine.ext import webapp import re MY_SECRET_KEY = 'MAKE UP PASSWORD HERE' # make one up, use the same one in the shell command cookie_re = re.compile('^"?([^:]+):.*"?$') class ApiCallHandler(handler.ApiCallHandler): def CheckIsAdmin(self): """Determine if admin access should be granted based on the auth cookie passed with the request.""" login_cookie = self.request.cookies.get('dev_appserver_login', '') match = cookie_re.search(login_cookie) if (match and match.group(1) == MY_SECRET_KEY and 'X-appcfg-api-version' in self.request.headers): return True else: self.redirect('/_ah/login') return False app = webapp.WSGIApplication([('.*', ApiCallHandler)]) 

From here we script load the data that was exported from our live application. Use the same password you created in the python script above.

 echo "MAKE UP PASSWORD HERE" | appcfg.py upload_data --email=some@example.org --passin --url=http://localhost:8080/remoteapi --num_threads=4 --kind=WebHook --filename=webhook.data --db_filename=bulkloader-progress-webhook.sql3 

WebHook and webhook.data are related to Kind , which we exported from production.

+1
source share

You cannot use the appcfg.py upload_data with the development server [edit: as is; see Josh J answer]. It only works with the remote_api endpoint running in App Engine and authenticates with OAuth2.

An easy way to load data into the dev server data store is to create an endpoint that reads the CSV file and creates the corresponding data store objects, and then deletes it using a browser. (Be sure to remove the endpoint before deploying the application or restrict access to the URL using login: admin .)

+1
source share

I had a similar problem where appcfg.py did not provide me with any credentials, so I could not authenticate. I downgraded 1.27 from GAELauncher to 1.26, and authentication started working again.

Workaround: Go to https://console.developers.google.com/storage/browser/appengine-sdks/featured/ to get version 1.9.26

Sent error report: https://code.google.com/p/google-cloud-sdk/issues/detail?id=340

+1
source share

You must have an oauth token for the google account that is not the administrator of this project. Try passing the --no_cookies flag to request authentication again.

0
source share

Maybe this has something to do with it? From the documents

Connecting your application to a local development server

To use the local development server for your local application, you need to do the following:

Set environment variables. Add or change the application Datastore connection code. Setting environment variables

Create the DATASTORE_HOST environment variable and set it on the host and port on which the local development server listens. The default host and port is http: // localhost: 8080 . (Note: if you use a port and / or command line to change these default values, be sure to set DATASTORE_HOST accordingly.) The following bash shell example shows how to set this variable:

export DATASTORE_HOST = http: // localhost: 8080 Create an environment variable called DATASTORE_DATASET and set it to your dataset identifier, as shown in the following bash shell example:

export DATASTORE_DATASET = Note: Both Python and Java client libraries look for the DATASTORE_HOST and DATASTORE_DATASET environment variables.

Link to documents

https://cloud.google.com/datastore/docs/tools/devserver

0
source share

All Articles