Google app engine GAE-Python+;谷歌云存储授权问题

Google app engine GAE-Python+;谷歌云存储授权问题,google-app-engine,google-cloud-storage,Google App Engine,Google Cloud Storage,我正在尝试运行一个Google云存储+Google应用程序引擎(Python)“Hello world”应用程序 我按照说明激活了谷歌云存储,并在我的应用程序引擎的控制台中创建了一个存储桶。我编写了一个简单的程序来编写测试文件,但当我运行它时,云存储库抛出一个403,显然是因为我的应用程序引擎应用程序的凭据没有显示、无效,或者没有此存储桶的权限 代码如下: BUCKET = '/pcj-info-testing' class TestGCS(webapp2.RequestHandler):

我正在尝试运行一个Google云存储+Google应用程序引擎(Python)“Hello world”应用程序

我按照说明激活了谷歌云存储,并在我的应用程序引擎的控制台中创建了一个存储桶。我编写了一个简单的程序来编写测试文件,但当我运行它时,云存储库抛出一个403,显然是因为我的应用程序引擎应用程序的凭据没有显示、无效,或者没有此存储桶的权限

代码如下:

BUCKET = '/pcj-info-testing'

class TestGCS(webapp2.RequestHandler):
  def create_file(self, filename):
    self.response.write("Creating\n");
    gcs_file = gcs.open(filename, 'w', content_type = 'text/plain');
    gcs_file.write('Testing, 1, 2, 3\n')
    gcs_file.write('At ' + datetime.now().isoformat())    
    gcs_file.close()

  def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    filename = BUCKET + "/demo-file" + str(random.randrange(10**10, 10**11-1))
    self.create_file(filename)
    self.response.write('File stat:\n')
    stat = gcs.stat(filename)
    self.response.write(repr(stat))
下面是堆栈跟踪和错误的相关部分:

  File "/base/data/home/apps/s~pcj-info/1.373629132682543570/gcstest.py", line 14, in create_file
    gcs_file = gcs.open(filename, 'w', content_type = 'text/plain');
  File "/base/data/home/apps/s~pcj-info/1.373629132682543570/cloudstorage/cloudstorage_api.py", line 74, in open
    return storage_api.StreamingBuffer(api, filename, content_type, options)
  File "/base/data/home/apps/s~pcj-info/1.373629132682543570/cloudstorage/storage_api.py", line 597, in __init__
    errors.check_status(status, [201], path, headers, resp_headers)
  File "/base/data/home/apps/s~pcj-info/1.373629132682543570/cloudstorage/errors.py", line 106, in check_status
    raise ForbiddenError(msg)
ForbiddenError: Expect status [201] from Google Storage. But got status 403.
Path: '/pcj-info-testing/demo-file16955619179'.
Request headers: {'x-goog-resumable': 'start', 'x-goog-api-version': '2', 'content-type': 'text/plain', 'accept-encoding': 'gzip, *'}.
Response headers: {'alternate-protocol': '443:quic', 'content-length': '146', 'via': 'HTTP/1.1 GWA', 'x-google-cache-control': 'remote-fetch', 'vary': 'Origin', 'server': 'HTTP Upload Server Built on Jan 23 2014 15:07:07 (1390518427)', 'date': 'Sat, 08 Feb 2014 16:49:56 GMT', 'content-type': 'application/xml; charset=UTF-8'}.
Extra info: None.
我已经查看了bucket上的访问权限,它们看起来是正确的(尽管根据文档,默认情况下它们应该是正确创建的)——在中列出的ID与bucket权限中列出的ID相同,具有所有者权限

我可以理解Google可能在其应用程序中返回403的原因,但据我所知,在应用程序引擎中进行调用的urlfetch库不会返回这些错误名称(我假设它们是错误代码之后HTTP响应中返回的文本字符串,但我想库只提供整数结果)。所以我不知道下一步该怎么办

有没有直接的方法来捕获API返回的错误?如果我知道错误是AccountProblem vs.InvalidSecurity或其他什么,我的故障排除会有很大的不同。非常令人沮丧的是,API返回错误代码的方式对于在受支持的云开发平台上使用推荐库的用户来说是不可访问的


如果我给“所有经过身份验证的用户”写权限,它就可以工作。因此,看起来我正在作为某人进行身份验证,但该某人不在权限列表中。添加我在测试应用程序时登录的Gmail帐户没有帮助。(该应用程序需要管理员登录才能点击所有URL。)

您需要将appengine服务帐户添加为具有写入权限


您可以在appengine控制台的“应用程序设置”下的“服务帐户名称”下找到服务帐户电子邮件。

我想您已经用oauth授权了应用程序?我没有;AppEngine文档声称,它们会自动传递将应用程序标识为已授权的凭据,但它们显然是不完整的@杰特拉斯的回答对我有用。谢谢,非常感谢!你能告诉我这是否是我忽略的直接记录,或者我的挫折是正义的吗?我当然在云存储客户端API文档或链接到页面的任何地方都找不到它。我刚刚发现这个问题,我必须做同样的事情,将服务帐户添加到Google Bucket权限。默认存储桶不是使用App Engine的所有正确权限创建的。