【问题标题】:Issue with using cloudstorage module in python在 python 中使用 cloudstorage 模块的问题
【发布时间】:2018-07-04 18:43:40
【问题描述】:

我正在尝试从一系列 URL 直接上传到 Google Cloud Storage。我一直在尝试在这里实现解决方案: How to upload an image from web into Google Cloud Storage?

特别是,每当我尝试使用 cloudstorage 模块打开文件时,

options={'x-goog-acl': 'public-read', 'Cache-Control': 'private, max-age=0, no-transform'}
with gcs.open(filename, 'w', content_type=content_type, options=options) as f:
    f.write(image_bytes)

我收到以下错误:


AttributeError                            Traceback (most recent call last)
<ipython-input-8-dec1a5d39c62> in <module>()
     18 
     19 options={'x-goog-acl': 'public-read', 'Cache-Control': 'private, max-age=0, no-transform'}
---> 20 with gcs.open(filename, 'w', content_type=content_type, options=options) as f:
     21     f.write(image_bytes)
     22     f.close()

AttributeError: 'module' object has no attribute 'open'

我已经尝试在隔离环境中安装 cloudstorage,但仍然没有成功。

根据下面的参考,cloudstorage.open() 存在于 https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/functions

知道问题出在哪里吗?

谢谢!

【问题讨论】:

标签: python google-app-engine cloud-storage


【解决方案1】:

print dir(gcs) 看看里面有什么。您可能正在安装一个名称相似但不同的软件包。

听起来这就是你想要的

https://github.com/GoogleCloudPlatform/appengine-gcs-client/tree/master/python/src/cloudstorage

这是您尝试使用的功能:

https://github.com/GoogleCloudPlatform/appengine-gcs-client/blob/master/python/src/cloudstorage/cloudstorage_api.py#L47

这个 repo 的 readme.md 指向这里:

https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/setting-up-cloud-storage

说要这样做:

pip install GoogleAppEngineCloudStorageClient -t &lt;your_app_directory/lib&gt;

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-22
  • 1970-01-01
  • 1970-01-01
  • 2013-06-14
  • 2022-07-06
  • 2012-11-14
  • 2015-09-13
相关资源
最近更新 更多