Google API Python 客户端 ( http://code.google.com/p/google-api-python-client/ ) 有一个示例应用程序在 Google App Engine 基础架构上演示 OAUTH2。这可以在以下位置找到:
http://code.google.com/p/google-api-python-client/source/browse/#hg%2Fsamples%2Fappengine
我试着抓住这个例子,用我的应用程序的凭据填写 client_secrets.json,但使用本地 dev_appserver 运行我得到:
WARNING 2012-02-16 20:52:45,650 rdbms_mysqldb.py:94] The rdbms API is not available because the MySQLdb library could not be loaded.
INFO 2012-02-16 20:52:45,729 appengine_rpc.py:159] Server: appengine.google.com
INFO 2012-02-16 20:52:45,731 appcfg.py:561] Checking for updates to the SDK.
INFO 2012-02-16 20:52:46,008 appcfg.py:579] The SDK is up to date.
WARNING 2012-02-16 20:52:46,009 datastore_file_stub.py:512] Could not read datastore data from /tmp/dev_appserver.datastore
INFO 2012-02-16 20:52:46,036 dev_appserver_multiprocess.py:639] Running application dev~pzelnip on port 8080: http://localhost:8080
INFO 2012-02-16 20:52:46,036 dev_appserver_multiprocess.py:641] Admin console is available at: http://localhost:8080/_ah/admin
ERROR 2012-02-16 20:52:48,921 cgi.py:121] Traceback (most recent call last):
File "/home/aparkin/temp/gae_oauth_demo/google-api-python-client/samples/appengine/main.py", line 28, in <module>
import httplib2
File "/home/aparkin/Downloads/gae_newer/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/home/aparkin/Downloads/gae_newer/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1845, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "/home/aparkin/Downloads/gae_newer/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/home/aparkin/Downloads/gae_newer/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1717, in FindAndLoadModule
description)
File "/home/aparkin/Downloads/gae_newer/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 676, in Decorate
return func(self, *args, **kwargs)
File "/home/aparkin/Downloads/gae_newer/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1660, in LoadModuleRestricted
description)
File "/home/aparkin/temp/gae_oauth_demo/google-api-python-client/samples/appengine/httplib2/__init__.py", line 64, in <module>
_ssl_wrap_socket = ssl.wrap_socket
AttributeError: 'module' object has no attribute 'wrap_socket'
当我使用 appcfg.py 在 GAE 上实时部署应用程序时,当我转到应用程序的根页面时,我收到 500 服务器错误,并且开发控制台日志显示:
2012-02-16 12:53:59.271 / 500 1079ms 0kb Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
64.251.74.12 - - [16/Feb/2012:12:53:59 -0800] "GET / HTTP/1.1" 500 0 - "Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1" "pzelnip.appspot.com" ms=1079 cpu_ms=373 api_cpu_ms=0 cpm_usd=0.010403 loading_request=1 instance=00c61b117c31344046c8b30771918918ee8d
E 2012-02-16 12:53:59.269
Traceback (most recent call last):
File "/base/data/home/apps/s~pzelnip/1.356864969797552635/main.py", line 34, in <module>
from oauth2client.appengine import oauth2decorator_from_clientsecrets
File "/base/data/home/apps/s~pzelnip/1.356864969797552635/oauth2client/appengine.py", line 40, in <module>
from client import AccessTokenRefreshError
File "/base/data/home/apps/s~pzelnip/1.356864969797552635/oauth2client/client.py", line 63, in <module>
CACHED_HTTP = httplib2.Http('.cache')
File "/base/data/home/apps/s~pzelnip/1.356864969797552635/httplib2/__init__.py", line 803, in __init__
self.cache = FileCache(cache)
File "/base/data/home/apps/s~pzelnip/1.356864969797552635/httplib2/__init__.py", line 649, in __init__
os.makedirs(self.cache)
File "/base/python27_runtime/python27_dist/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 38] Function not implemented: '.cache'
所以嗯,救命?
FWIW,我确实按照将整个客户端代码复制到应用程序引擎项目的说明进行操作(如http://code.google.com/p/google-api-python-client/wiki/GoogleAppEngine中所述)