python - 在 python 中使用 cloudstorage 模块的问题

标签 python google-app-engine cloud-storage

我正在尝试从一系列网址直接上传到 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

知道问题出在哪里吗?

谢谢!

最佳答案

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 <your_app_directory/lib>

关于python - 在 python 中使用 cloudstorage 模块的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51179455/

相关文章:

java - 如何在 GAE 上向 HtmlUnit webclient 添加 cookie

ide - 使用 Google Drive(或任何云存储)作为开发工作区?

cassandra - 与 apache cassandra 一起使用的最佳数据存储文件系统?

python - 如何使用 cv2 计算图像中的不同颗粒?

python - 在同一行上创建 for 语句,但不在下一个输入上创建 for 语句

java - getServingUrl() 方法使用谷歌云存储值

javascript - 使用 AWS S3 存储桶的授权错误

python - + : 'dict' and 'int' 不支持的操作数类型

python - 将 xml 转换为 python 字典

java - AppEngine 和 Android (REST)