首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从本地python应用访问google云存储?

如何从本地python应用访问google云存储?
EN

Stack Overflow用户
提问于 2016-08-30 07:32:33
回答 1查看 542关注 0票数 1

当我的应用程序部署到gae时,我可以访问gcs,但我希望在开发期间从我的本地计算机访问gcs。我该怎么做呢?

以下是我尝试在gcs上打开文件时得到的回溯:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-30 15:31:48

啊,看起来你使用的是Python的appengine-gcs-client。当在本地开发服务器上运行时,客户机默认为使用本地的伪GCS版本(参见响应头" server : Development/2.0"?)。我猜你要找的是一个真正的GCS对象,你还没有上传到本地的假的。

你可以通过上传有问题的对象作为服务器初始化的一部分,使用不同的库(gcloud-python真的很好),或者禁用本地fake,这可以通过设置SERVER_SOFTWARE环境变量来实现:

代码语言:javascript
复制
# 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'
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39216702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档