appcfg.py显示您必须以管理员身份登录

Avi*_*Raj 8 python google-app-engine

当我尝试将示例csv数据上传到我的GAE应用程序时appcfg.py,它会显示以下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 ---
Run Code Online (Sandbox Code Playgroud)

这是我试过的命令,

appcfg.py upload_data --application=dev~app --url=http://localhost:8080/_ah/remote_api --filename=data/sample.csv
Run Code Online (Sandbox Code Playgroud)

Jos*_*h J 1

这就是我们使用自定义身份验证的方式。

app.yaml中的自定义处理程序

- url: /remoteapi.*
  script: remote_api.app
Run Code Online (Sandbox Code Playgroud)

在remote_api.py中自定义wsgi应用程序来覆盖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)])
Run Code Online (Sandbox Code Playgroud)

从这里,我们编写从实时应用程序导出的数据上传的脚本。使用您在上面的 python 脚本中设置的相同密码。

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
Run Code Online (Sandbox Code Playgroud)

WebHook并且webhook.data特定于Kind我们从生产中导出的产品。