我正在尝试使用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'",))
答案 0 :(得分:1)
按照How the Application Default Credentials work(条件1)
中的说明进行操作它涉及将GOOGLE_APPLICATION_CREDENTIALS env变量设置为指向有效的json凭证文件。 对于这些测试,我刚刚创建了一个新的选择App Engine默认服务帐户:
......而且效果很好。
根据How the Application Default Credentials work运行gcloud auth application-default login
(条件2)也应解决问题,但我无法使其在Cloud Shell上运行,它失败并使用相同的“访问令牌相关”错误: - (
答案 1 :(得分:0)
dev_appserver.py使用您在本地环境中设置的配置。确保gcloud init
上设置的配置对于部署到生产也是正确的。
要设置云存储帐户权限,请转到云控制台:
存储>浏览器>你的水桶的右按钮>编辑存储桶权限
将您的帐户添加为Storage Admin等。
答案 2 :(得分:0)
确保您已登录并已授权默认服务凭据。
% gcloud auth login
% gcloud auth application-default login