gsutil 下载错误 serviceexception 401 anonymous caller does not have storage objects list

Windows 2021-07-12 阅读 904 评论 0

问题描述

使用浏览器访问 Google Cloud Storage,有一些存储需要登录谷歌账号才能访问,使用 gsutil 下载或者访问这些资源时,会出现:401 匿名调用者没有存储对象列表的错误。如下:

$ gsutil -m cp -r "gs://waymo_open_dataset_v_1_2_0/" .
ServiceException: 401 Anonymous caller does not have storage.objects.list access to the Google Cloud Storage bucket.
CommandException: 1 file/object could not be transferred.

解决方法

使用gsutil config命令获取 Cloud Storage 的访问凭据,并写入一个 boto/gsutil 配置文件其中包含获取的凭据以及许多其他配置可控值。参考gsutil config 官方文档

运行如下:

$ gsutil config
This command will create a boto config file at
C:\Users\Administrator\.boto containing your credentials, based on
your responses to the following questions.
Please navigate your browser to the following URL:
https://accounts.google.com/o/oauth2/auth?client_id=912341233072.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&access_type=offline&response_type=code
In your browser you should see a page that requests you to authorize access to Google Cloud Platform APIs and Services on your behalf. After you approve, an authorization code will be displayed.

Enter the authorization code: 4/1AX4XfWjTqe2CzuheTvIJ-Ibq123RHl7-kp2XygdJoXDz5BZbFjaCkLgflg

Please navigate your browser to https://cloud.google.com/console#/project,
then find the project you will use, and copy the Project ID string from the
second column. Older projects do not have Project ID strings. For such projects,
 click the project and then copy the Project Number listed under that project.

What is your project-id? quickstart-1123408928142

gsutil developers rely on user feedback to make improvements to the
tool. Would you like to send anonymous usage statistics to help
improve gsutil? [y/N] y

Boto config file "C:\Users\Administrator\.boto" created. If you need
to use a proxy to access the Internet please see the instructions in
that file.

按照命令的提示,分别输入登录授权后的 authorization code 和 project-id 即可。

配置完成后,可以获取储存大小或者复制等操作。如快速获取存储块的总大小:

$ gsutil du -hs "gs://waymo_open_dataset_v_1_2_0/"
1.82 TiB     gs://waymo_open_dataset_v_1_2_0
最后更新 2021-07-12
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });