From 54762c22175e17dce4f4eab18c5942c06e82478f Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Wed, 19 Apr 2023 02:59:58 +0000 Subject: [PATCH] Handle 401 from gsutil Instruct user to use gsutil.py config if they get 401 from gsutil operation. Setting project ID is no longer applicable. R=aravindvasudev@google.com Bug: 1433494 Change-Id: Ibbb22a9b5bb3a92e35f689371701eb051b38c202 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4442760 Auto-Submit: Josip Sokcevic Reviewed-by: Aravind Vasudevan Commit-Queue: Aravind Vasudevan --- download_from_google_storage.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/download_from_google_storage.py b/download_from_google_storage.py index 58d4913cb..d8093ad27 100755 --- a/download_from_google_storage.py +++ b/download_from_google_storage.py @@ -121,10 +121,12 @@ class Gsutil(object): status_code_match = re.search('status=([0-9]+)', err) if status_code_match: return (int(status_code_match.group(1)), out, err) + if ('ServiceException: 401 Anonymous' in err): + return (401, out, err) if ('You are attempting to access protected data with ' 'no configured credentials.' in err): return (403, out, err) - if 'matched no objects' in err: + if 'matched no objects' in err or 'No URLs matched' in err: return (404, out, err) return (code, out, err) @@ -296,8 +298,8 @@ def _downloader_worker_thread(thread_num, q, force, base_url, elif code == 401: out_q.put( """%d> Failed to fetch file %s for %s due to unauthorized access, - skipping. Try running `gsutil.py config` and pass 0 if you don't - know your project id.""" % (thread_num, file_url, output_filename)) + skipping. Try running `gsutil.py config`.""" % + (thread_num, file_url, output_filename)) ret_codes.put( (1, 'Failed to fetch file %s for %s due to unauthorized access.' % (file_url, output_filename)))