gpt4 book ai didi

google-app-engine - Cloud Shell 上的 dev_appserver 上的 Google Cloud 存储

转载 作者:太空宇宙 更新时间:2023-11-03 15:30:12 27 4
gpt4 key购买 nike

我正在尝试使用来自 GAE 的 Google Cloud Storage,并且在部署时一切正常。但是,我无法让存储在 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 .

有人吗?

编辑:无论我提供有效还是无效的存储桶名称,我都会收到相同的错误。

应用.yaml

runtime: python27
api_version: 1
threadsafe: true

builtins:
- remote_api: on

handlers:
- url: /.*
script: main.app

主要.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 环境变量以指向有效的 json 凭据文件。对于这些测试,我刚刚创建了一个选择 App Engine 默认服务帐户的新帐户:

App Engine default service account

...而且效果很好。

根据 How the Application Default Credentials work运行 gcloud auth application-default login(条件 2.)也应该可以解决问题,但我无法使其在 Cloud Shell 上运行,它失败并出现相同的“访问 token 相关”错误: -(

关于google-app-engine - Cloud Shell 上的 dev_appserver 上的 Google Cloud 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44423085/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com