質問編集履歴

4

エラーメッセージを修正

2018/02/22 01:02

投稿

nedisoh
nedisoh

スコア74

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 [project-name].
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

エラーメッセージを修正

2018/02/22 01:02

投稿

nedisoh
nedisoh

スコア74

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/[project-name]?projection=noAcl: [service-account-id]@[project-id] does not have storage.buckets.get access to [project-name].
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

ソースコードを実際のものに変更

2018/02/22 01:01

投稿

nedisoh
nedisoh

スコア74

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('my-bucket')
35
+ bucket = storage_client.get_bucket(BUCKET_NAME)
32
36
 
33
- except google.cloud.exceptions.
37
+ except NotFound:
34
38
 
39
+ # バケットが無い場合
40
+
35
- print('Sorry, that bucket does not exist!')
41
+ bucket = storage_client.create_bucket(BUCKET_NAME)
36
42
 
37
43
  ```
38
44
 

1

質問の内容が根本的にずれていたため修正しました。

2018/02/22 00:35

投稿

nedisoh
nedisoh

スコア74

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
- storage_client = storage.Client()
29
+ try:
28
30
 
29
- bucket = storage_client.create_bucket(bucket_name)
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