Я хочу создать корзину в облаке Google с Python.
Ключ учетной записи моей службы имеет следующий формат:
{
"type": "service_account",
"project_id": "project-15891817892",
"private_key_id": "89347sdjlf56khk",
"private_key": "-----BEGIN PRIVATE KEY-----\nabcdefghi==\n-----END PRIVATE KEY-----\n",
"client_email": "starting-account-dslkfjal983475sd@project-15891817892.iam.gserviceaccount.com",
"client_id": "729387492879034579812",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/starting-account-dslkfjal983475sd%40project-15891817892.iam.gserviceaccount.com"
}
Я добавил следующие роли:
Actions Admin
AutoML Admin
Bigtable Administrator
Cloud Data Fusion Admin
Service Account Admin
Owner
Cloud Run Admin
Service Broker Admin
Service Usage Admin
Storage Admin
Storage HMAC Key Admin
Storage Object Admin
Storage Object Creator
Storage Transfer Admi
Вот код Python:
from google.cloud import storage
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = r'C:\project-934875sddklf32.json'
storage_client = storage.Client()
bucket_name = 'data'
bucket = storage_client.create_bucket(bucket_name)
Однако я получил следующую ошибку:
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
list_buckets()
File "C:\gcloud\test.py", line 109, in list_buckets
for bucket in buckets:
File "C:\Program Files\Python37\lib\site-packages\google\api_core\page_iterator.py", line 204, in _items_iter
for page in self._page_iter(increment=False):
File "C:\Program Files\Python37\lib\site-packages\google\api_core\page_iterator.py", line 235, in _page_iter
page = self._next_page()
File "C:\Program Files\Python37\lib\site-packages\google\api_core\page_iterator.py", line 361, in _next_page
response = self._get_next_page_response()
File "C:\Program Files\Python37\lib\site-packages\google\api_core\page_iterator.py", line 411, in _get_next_page_response
method=self._HTTP_METHOD, path=self.path, query_params=params
File "C:\Program Files\Python37\lib\site-packages\google\cloud\_http.py", line 393, in api_request
raise exceptions.from_http_response(response)
google.api_core.exceptions.Forbidden: 403 GET https://www.googleapis.com/storage/v1/b?project-89324y9sdhfks&projection=noAcl: starting-account-934875dlkjfls@project-jsdlkjf9ulsj.iam.gserviceaccount.com does not have storage.buckets.list access to project 2093472972.
Почему возникает эта ошибка и как ее решить?