我是 Python 和 Google Cloud Storage 新手。
我正在编写一个 python 脚本,以使用 Google Cloud Python 客户端库从 Google Cloud Storage 存储桶获取文件列表,而 Bucket 类中的 list_blobs() 函数无法按我的预期工作。
https://googlecloudplatform.github.io/google-cloud-python/stable/storage-buckets.html
这是我的Python代码:
from google.cloud import storage
from google.cloud.storage import Blob
client = storage.Client.from_service_account_json(service_account_json_key_path, project_id)
bucket = client.get_bucket(bucket_id)
print(bucket.list_blobs())
如果我正确理解文档, print(bucket.list_blobs()) 应该打印如下内容:['testfile.txt', 'testfile2.txt']。
然而,我的脚本打印了这个:
“google.cloud.storage.bucket._BlobIterator 对象位于 0x7fdfdbcac590”
delete_blob() 文档的示例代码与我的相同。https://googlecloudplatform.github.io/google-cloud-python/stable/storage-buckets.html
我不确定我在这里做错了什么。
任何指示/示例/答案将不胜感激。谢谢!
列表函数示例:
def list_blobs(bucket_name):
"""Lists all the blobs in the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blobs = bucket.list_blobs()
for blob in blobs:
print(blob.name)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)