0
當使用聯合登錄時,Google App Engine的Remote API爲not supported。但是,顯然有可能在Python 2.5使用它,如下所述:如何在Python 2.7中使用Google App Engine遠程API和聯合登錄?
http://blog.notdot.net/2010/06/Using-remote-api-with-OpenID-authentication
基於該解決方案,我創建了下面的Python 2.7的代碼的文章下面的評論:
應用.yaml:
application: my_application
version: 1
runtime: python27
api_version: 1
threadsafe: true
builtins:
- appstats: on
#- remote_api: on
handlers:
- url: /remoteapi.*
script: remote_api.app
- url: /.*
script: main.app
secure: never
remote_api.py:
from google.appengine.ext.remote_api import handler
from google.appengine.ext import webapp
import re
MY_SECRET_KEY = 'secret'
cookie_re = re.compile('^"?([^:]+):.*"?$')
class ApiCallHandler(handler.ApiCallHandler):
def CheckIsAdmin(self):
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)])
當我運行remote_api_shell命令:
remote_api_shell.py -s my_application.appspot.com/remoteapi
返回此錯誤:
Traceback (most recent call last):
File "remote_api_shell.py", line 133, in <module>
run_file(__file__, globals())
File "remote_api_shell.py", line 129, in run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\re
mote_api_shell.py", line 140, in <module>
main(sys.argv)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\re
mote_api_shell.py", line 136, in main
appengine_rpc.HttpRpcServer)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\re
mote_api_shell.py", line 76, in remote_api_shell
rpc_server_factory=rpc_server_factory)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\remo
te_api\remote_api_stub.py", line 682, in ConfigureRemoteApi
app_id = GetRemoteAppIdFromServer(server, path, rtok)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\remo
te_api\remote_api_stub.py", line 525, in GetRemoteAppIdFromServer
response = server.Send(path, payload=None, **urlargs)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\ap
pengine_rpc.py", line 366, in Send
f = self.opener.open(req)
File "C:\Python27\lib\urllib2.py", line 400, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 513, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 438, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 372, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 521, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 302: Found
什麼是錯我的代碼?使用聯合登錄可以在Google App Engine上的Python 2.7中使用Remote API嗎?