我正在尝试使用GAE的Google云端存储,部署后一切正常.但是,我无法让存储在Google Cloud
Shell上运行的开发服务器上运行.
我正在使用cloudstorage API并且我理解dev_appserver应该访问与已部署的应用程序相同的存储桶.对我来说,使用本地数据也可以.
dev_appserver.py调用开发服务器.
我玩过未记录的default_gcs_bucket_name标志,但没有运气.
我使用gcloud init设置了cloud shell以使用正确的项目.我也尝试过使用新的google.cloud.storage API而没有运气.
如果我运行此处提供的示例,则会触发与下面引用的相同的错误:App Engine and Google Cloud Storage Sample.
任何人?
编辑:无论是否提供有效或无效的存储桶名称,我都会收到相同的错误.
的app.yaml
runtime: python27
api_version: 1
threadsafe: true
builtins:
- remote_api: on
handlers:
- url: /.*
script: main.app
main.py
import logging
import cloudstorage as gcs
import webapp2
from google.appengine.api import app_identity
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
bucket_name = "xxxx-xxxxxx.appspot.com"
stats = gcs.listbucket('/'+bucket_name)
for stat in stats:
self.response.write(repr(stat) + '')
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
日志
INFO 2017-06-07 20:36:42,068 devappserver2.py:116] Skipping SDK update check.
INFO 2017-06-07 20:36:42,105 api_server.py:297] Starting API server at: http://0.0.0.0:38829
INFO 2017-06-07 20:36:42,110 dispatcher.py:209] Starting module "default" running at: http://0.0.0.0:8080
INFO 2017-06-07 20:36:42,111 admin_server.py:116] Starting admin server at: http://0.0.0.0:8000
ERROR 2017-06-07 20:36:54,836 api_server.py:374] Exception while handling service_name: "app_identity_service"
method: "GetAccessToken"
request: "\n7https://www.googleapis.com/auth/devstorage.full_control"
request_id: "QBrGUwjoJT"
Traceback (most recent call last):
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 349, in _handle_POST
api_response = _execute_request(request).Encode()
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 225, in _execute_request
make_request()
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/api_server.py", line 220, in make_request
request_id)
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/api/apiproxy_stub.py", line 131, in MakeSyncCall
method(request, response)
File "/google/google-cloud-sdk/platform/google_appengine/google/appengine/api/app_identity/app_identity_defaultcredentialsbased_stub.py", line 195, in _Dynamic_GetAccessToken
'expires': now + token.expires_in,
TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'
WARNING 2017-06-07 20:36:54,838 tasklets.py:468] suspended generator _make_token_async(rest_api.py:55) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator get_token_async(rest_api.py:224) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator urlfetch_async(rest_api.py:259) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator run(api_utils.py:164) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator do_request_async(rest_api.py:198) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
WARNING 2017-06-07 20:36:54,839 tasklets.py:468] suspended generator do_request_async(storage_api.py:137) raised RuntimeError(TypeError("unsupported operand type(s) for +: 'int' and 'NoneType'",))
最佳答案 按照
How the Application Default Credentials work中的说明进行操作(条件1)
它涉及将GOOGLE_APPLICATION_CREDENTIALS env变量设置为指向有效的json凭证文件.
对于这些测试,我刚刚创建了一个新的选择App Engine默认服务帐户:
……而且效果很好.
根据How the Application Default Credentials work运行gcloud auth应用程序 – 默认登录(条件2)也应该解决问题,但我还没能使它在Cloud Shell上运行,它失败了同样的“访问令牌相关”错误:-(