我有一个带有以下树的 Google 存储桶(注意名为“/”的文件夹!):
"bucket-1"
|
|--- "data.csv"
|
|--- "/"
|
|--- "runs"
|
|--- "run-1"
| |
| |--- "data.csv"
|
|--- "run-2"
|
|--- "data.csv"
我想使用子文件夹“/”中的 Python 库 libcloud 访问对象(.csv 文件)。
我可以访问data.csv
“/”文件夹之外的内容:
>>> client.get_object(container_name='bucket-1', object_name='/data.csv')
<Object: name=/data.csv, size=181580, hash=8252d90d95b7b1cb7b4e699b90fbcce3, provider=Google Cloud Storage ...>
使用带有两个斜杠的 gsutil 我可以在“/”中看到对象:
>>> gsutil ls "gs://bucket-1//runs/run-1"
gs://bucket-1//runs/run-1/data.csv
client.get_object(container_name='bucket-1', object_name='//runs/run-1/data.csv')
但是,如果我这样做或者client.get_object(container_name='bucket-1', object_name='/runs/run-1/data.csv')
我收到错误,则使用 libcloud :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/andrey/miniconda3/envs/mostly-cloud/lib/python3.6/site-packages/libcloud/storage/drivers/s3.py", line 342, in get_object
object_name=object_name)
libcloud.storage.types.ObjectDoesNotExistError: <ObjectDoesNotExistError in <libcloud.storage.drivers.google_storage.GoogleStorageDriver object at 0x7f40560cd4e0>, value=None, object = //runs/run-1/data.csv>
另一方面,
client.list_container_objects(client.get_container("bucket-1"))
[<Object: name=/runs/run-1/data.csv, size=357683, hash=..., provider=Google Cloud Storage ...>, <Object: name=/runs/run-2/data.csv, size=357683, hash=..., provider=Google Cloud Storage ...>]
那么,如何获取位于“/”目录下的对象呢?