1

當我的應用程序部署到gae時,我可以訪問gcs,但我想在開發過程中從本地機器訪問gcs。我會如何去做這件事?如何從本地python應用程序訪問谷歌雲存儲?

這裏是回溯我得到當我試圖打開一個文件上GCS:

Traceback (most recent call last): 
    File "/Users/alvinsolidum/Downloads/google_appengine/google/appengine/runtime/wsgi.py", line 267, in Handle 
    result = handler(dict(self._environ), self._StartResponse) 
    File "/Users/alvinsolidum/Downloads/google_appengine/lib/webapp2-2.3/webapp2.py", line 1519, in __call__ 
    response = self._internal_error(e) 
    File "/Users/alvinsolidum/Downloads/google_appengine/lib/webapp2-2.3/webapp2.py", line 1511, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/Users/alvinsolidum/Downloads/google_appengine/lib/webapp2-2.3/webapp2.py", line 1505, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/Users/alvinsolidum/Downloads/google_appengine/lib/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/Users/alvinsolidum/Downloads/google_appengine/lib/webapp2-2.3/webapp2.py", line 1077, in __call__ 
    return handler.dispatch() 
    File "/Users/alvinsolidum/Downloads/google_appengine/lib/webapp2-2.3/webapp2.py", line 547, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/Users/alvinsolidum/Downloads/google_appengine/lib/webapp2-2.3/webapp2.py", line 545, in dispatch 
    return method(*args, **kwargs) 
    File "/Users/alvinsolidum/Documents/fallsafety-dataflow/preprocess/main.py", line 74, in get 
    self.to_csv() 
    File "/Users/alvinsolidum/Documents/fallsafety-dataflow/preprocess/main.py", line 41, in to_csv 
    compressed_flo = gcs.open(read_filepath, 'r') 
    File "/Users/alvinsolidum/Documents/fallsafety-dataflow/preprocess/lib/cloudstorage/cloudstorage_api.py", line 103, in open 
    offset=offset) 
    File "/Users/alvinsolidum/Documents/fallsafety-dataflow/preprocess/lib/cloudstorage/storage_api.py", line 249, in __init__ 
    errors.check_status(status, [200], path, resp_headers=headers, body=content) 
    File "/Users/alvinsolidum/Documents/fallsafety-dataflow/preprocess/lib/cloudstorage/errors.py", line 132, in check_status 
    raise NotFoundError(msg) 
NotFoundError: Expect status [200] from Google Storage. But got status 404. 
Path: '/fallsafety-test-general/apple-watch/continuous/active/54d0044919e92b0c00c29555-29391CEA593C4D798A1EA08BD23DA47E-0002-continuous.csv.gz'. 
Request headers: None. 
Response headers: {'date': 'Mon, 29 Aug 2016 23:15:49 GMT', 'server': 'Development/2.0', 'connection': 'close'}. 
Body: ''. 
Extra info: None. 

回答

2

啊,它看起來像你使用的AppEngine-GCS-客戶端的Python。在本地開發服務器上運行時,客戶端默認使用本地假貨版本的GCS(請參閱響應頭「Server:Development/2.0」?)。我猜你正在尋找一個真正的GCS對象,你還沒有上傳到本地的假貨。

你可以通過上傳相關對象作爲服務器初始化的一部分,使用不同的庫(gcloud-python非常好)或禁用本地假,這可以通過設置SERVER_SOFTWARE環境變量:

# Logic for whether to use local fake is here: https://github.com/GoogleCloudPlatform/appengine-gcs-client/blob/f9dbbd43ec431f739aa33a44cf24d32a19579f33/python/src/cloudstorage/common.py#L387 
os.environ['SERVER_SOFTWARE'] = 'Development (remote_api)/1.0' 
相關問題