質問編集履歴
4
エラーメッセージを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
-
google.api_core.exceptions.Forbidden: 403 GET https://www.googleapis.com/storage/v1/b/[bucket-name]?projection=noAcl: [service-account-id]@[project-id] does not have storage.buckets.get access to [
|
17
|
+
google.api_core.exceptions.Forbidden: 403 GET https://www.googleapis.com/storage/v1/b/[bucket-name]?projection=noAcl: [service-account-id]@[project-id] does not have storage.buckets.get access to [bucket-name].
|
18
18
|
|
19
19
|
```
|
20
20
|
|
3
エラーメッセージを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
```
|
16
16
|
|
17
|
-
google.api_core.exceptions.Forbidden: 403 GET https://www.googleapis.com/storage/v1/b/[
|
17
|
+
google.api_core.exceptions.Forbidden: 403 GET https://www.googleapis.com/storage/v1/b/[bucket-name]?projection=noAcl: [service-account-id]@[project-id] does not have storage.buckets.get access to [project-name].
|
18
18
|
|
19
19
|
```
|
20
20
|
|
2
ソースコードを実際のものに変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,13 +26,19 @@
|
|
26
26
|
|
27
27
|
```python
|
28
28
|
|
29
|
+
storage_client = storage.Client()
|
30
|
+
|
31
|
+
|
32
|
+
|
29
33
|
try:
|
30
34
|
|
31
|
-
bucket = client.get_bucket(
|
35
|
+
bucket = storage_client.get_bucket(BUCKET_NAME)
|
32
36
|
|
33
|
-
except
|
37
|
+
except NotFound:
|
34
38
|
|
39
|
+
# バケットが無い場合
|
40
|
+
|
35
|
-
|
41
|
+
bucket = storage_client.create_bucket(BUCKET_NAME)
|
36
42
|
|
37
43
|
```
|
38
44
|
|
1
質問の内容が根本的にずれていたため修正しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
クライアントライブラリからCloud Storage
|
1
|
+
クライアントライブラリからCloud Storageのバケットを取得できない
|
test
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
pythonのクライアントライブラリからCloud Storage
|
5
|
+
pythonのクライアントライブラリからCloud Storageのバケットを取得したい。
|
6
|
+
|
7
|
+
バケットが存在しない場合には google.cloud.exceptions.NotFound が投げられる。
|
6
8
|
|
7
9
|
|
8
10
|
|
@@ -24,9 +26,13 @@
|
|
24
26
|
|
25
27
|
```python
|
26
28
|
|
27
|
-
|
29
|
+
try:
|
28
30
|
|
29
|
-
bucket =
|
31
|
+
bucket = client.get_bucket('my-bucket')
|
32
|
+
|
33
|
+
except google.cloud.exceptions.
|
34
|
+
|
35
|
+
print('Sorry, that bucket does not exist!')
|
30
36
|
|
31
37
|
```
|
32
38
|
|