Cloud Storage python客户端无法检索存储桶

时间:2018-11-22 18:41:18

标签: python-3.x google-cloud-platform google-cloud-storage google-compute-engine

我正在尝试使用python客户端库将blob写入云存储。我正在使用的VM具有读/写权限来存储,并且可以通过gsutil访问存储桶,但是python给了我以下错误

>>> from google.cloud import storage
>>> storage_client = storage.Client()
>>> bucket = storage_client.get_bucket("gs://<bucket name>")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/google/cloud/storage/client.py", line 225, in get_bucket
bucket.reload(client=self)
File "/usr/local/lib/python3.5/dist-packages/google/cloud/storage/_helpers.py", line 108, in reload
_target_object=self)
File "/usr/local/lib/python3.5/dist-packages/google/cloud/_http.py", line 293, in api_request
raise exceptions.from_http_response(response)
google.api_core.exceptions.NotFound: 404 GET https://www.googleapis.com/storage/v1/b/gs://<bucket name>?projection=noAcl: Not Found

1 个答案:

答案 0 :(得分:2)

Phix是正确的。您只需要指定存储区名称,而无需使用'gs://'。实际上,发现https://www.googleapis.com/storage/v1/b/bucket是被调用的API(例如存储桶:更新here)。还有更多关于Python的Google Cloud Storage API client libraryexample的使用方法。