2016-08-06 111 views
-1

我想讀從雲端儲存文件在部署的應用程序從雲端儲存讀取文件時,代碼很簡單:問題在谷歌的AppEngine

# -*- coding: utf-8 -*- 
from google.appengine.ext import deferred 
from google.appengine.ext import ndb 
import logging 
import os 
import cloudstorage as gcs 
import webapp2 

from google.appengine.api import app_identity 


class Handler(webapp2.RequestHandler): 
    def get(self): 
     bucket_name = os.environ.get('BUCKET_NAME', 
            app_identity.get_default_gcs_bucket_name()) 

     self.response.headers['Content-Type'] = 'text/plain' 
     self.response.write('Demo GCS Application running from Version: ' 
          + os.environ['CURRENT_VERSION_ID'] + '\n') 
     self.response.write('Using bucket name: ' + bucket_name + '\n\n') 
     gcs_file = gcs.open("/" + bucket_name + "/mylist.csv", mode="r") 
     line = gcs_file.readline() 
     self.response.write(line) 

app = webapp2.WSGIApplication([('/view', Handler)]) 

但是,當我acccess的頁面,我得到一個「500內部服務器錯誤」,並在日誌中我可以看到以下內容:

10:24:32.791 
suspended generator _make_token_async(rest_api.py:55) raised InternalError(5:) 
10:24:32.792 
suspended generator get_token_async(rest_api.py:224) raised InternalError(5:) 
10:24:32.792 
suspended generator urlfetch_async(rest_api.py:259) raised InternalError(5:) 
10:24:32.792 
Tasklet is <bound method _StorageApi.urlfetch_async of <cloudstorage.storage_api._StorageApi object at 0x10c98f90>> 
10:24:32.792 
Got exception "InternalError('5: ',)" from tasklet. 
10:24:32.792 
Retry in 0.1 seconds. 
10:24:32.922 
suspended generator _make_token_async(rest_api.py:55) raised InternalError(5:) 
10:24:32.922 
suspended generator get_token_async(rest_api.py:224) raised InternalError(5:) 
10:24:32.923 
suspended generator urlfetch_async(rest_api.py:259) raised InternalError(5:) 
10:24:32.923 
Got exception "InternalError('5: ',)" from tasklet. 

該頁面加載的罰款,如果我刪除該文件被打開就行了。

更新:我認爲這個問題與用戶{project-id}@appspot.gserviceaccount.com不存在於我的應用程序中有關,而且我無法將其添加回到我的項目中,因爲管理員頁面只允許我添加格式爲{username }@{project-id}.iam.gserviceaccount.com的用戶。

那麼有誰知道如何將這個用戶添加回項目?

在此先感謝

回答