我正在尝试从一系列网址直接上传到 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
这是您尝试使用的功能:
这里 repo 的 readme.md 指向:
它说要这样做:
pip install GoogleAppEngineCloudStorageClient -t <your_app_directory/lib>
关于python - 在 python 中使用 cloudstorage 模块的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51179455/