Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion google/cloud/storage/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@
_marker = object()


def _buckets_page_start(iterator, page, response):
"""Grab prefixes after a :class:`~google.cloud.iterator.Page` started.

:type iterator: :class:`~google.api_core.page_iterator.Iterator`
:param iterator: The iterator that is currently in use.

:type page: :class:`~google.cloud.api.core.page_iterator.Page`
:param page: The page that was just created.

:type response: dict
:param response: The JSON API response for a page of blobs.
"""
page.unreachable = tuple(response.get("unreachable", ()))
iterator.unreachable.update(page.unreachable)


class Client(ClientWithProject):
"""Client to bundle configuration needed for API requests.

Expand Down Expand Up @@ -1551,7 +1567,7 @@ def list_buckets(
if soft_deleted is not None:
extra_params["softDeleted"] = soft_deleted

return self._list_resource(
iterator = self._list_resource(
"/b",
_item_to_bucket,
page_token=page_token,
Expand All @@ -1560,7 +1576,10 @@ def list_buckets(
page_size=page_size,
timeout=timeout,
retry=retry,
page_start=_buckets_page_start,
)
iterator.unreachable = set()
return iterator

def restore_bucket(
self,
Expand Down
8 changes: 6 additions & 2 deletions samples/snippets/storage_list_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ def list_buckets():
"""Lists all buckets."""

storage_client = storage.Client()
buckets = storage_client.list_buckets()
buckets_iterator = storage_client.list_buckets()
if hasattr(buckets_iterator, "unreachable"):
print("Unreachable locations:", len(buckets_iterator.unreachable))
for location in buckets_iterator.unreachable:
print(location)

for bucket in buckets:
for bucket in buckets_iterator:
print(bucket.name)


Expand Down