From 6ec188a2394682e3a9299002db410ec01ad1eadd Mon Sep 17 00:00:00 2001 From: Pulkit Aggarwal Date: Wed, 19 Nov 2025 12:31:57 +0000 Subject: [PATCH 1/2] samples: add samples for partial list bucket --- .../storage_list_buckets_partial_success.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 samples/snippets/storage_list_buckets_partial_success.py diff --git a/samples/snippets/storage_list_buckets_partial_success.py b/samples/snippets/storage_list_buckets_partial_success.py new file mode 100644 index 000000000..0b587e5ae --- /dev/null +++ b/samples/snippets/storage_list_buckets_partial_success.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python + +# Copyright 2025 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START storage_list_buckets_partial_success] +from google.cloud import storage + + +def list_buckets_with_partial_success(): + """Lists buckets and includes unreachable buckets in the response.""" + + storage_client = storage.Client() + + buckets_iterator = storage_client.list_buckets(return_partial_success=True) + + for page in buckets_iterator.pages: + if hasattr(page, "unreachable") and page.unreachable: + print("Unreachable locations in this page:") + for location in page.unreachable: + print(location) + + print("Reachable buckets in this page:") + for bucket in page: + print(bucket.name) + + +# [END storage_list_buckets_partial_success] + + +if __name__ == "__main__": + list_buckets_with_partial_success() From d9693362e31ebbc5dead7799a7d43bda27abd8bc Mon Sep 17 00:00:00 2001 From: Pulkit Aggarwal <54775856+Pulkit0110@users.noreply.github.com> Date: Wed, 19 Nov 2025 18:10:30 +0530 Subject: [PATCH 2/2] Update samples/snippets/storage_list_buckets_partial_success.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- samples/snippets/storage_list_buckets_partial_success.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/snippets/storage_list_buckets_partial_success.py b/samples/snippets/storage_list_buckets_partial_success.py index 0b587e5ae..bea4c9ed3 100644 --- a/samples/snippets/storage_list_buckets_partial_success.py +++ b/samples/snippets/storage_list_buckets_partial_success.py @@ -26,7 +26,7 @@ def list_buckets_with_partial_success(): buckets_iterator = storage_client.list_buckets(return_partial_success=True) for page in buckets_iterator.pages: - if hasattr(page, "unreachable") and page.unreachable: + if page.unreachable: print("Unreachable locations in this page:") for location in page.unreachable: print(location)