1

I am using following command to push all static files from my local Django project to bucket in Google cloud storage.

DJANGO_SETTINGS_MODULE=my_project.settings.production python manage.py collectstatic

settings/production.py


#----------------- Cloud Storage---------------------#
# Define static storage via django-storages[google]

GS_BUCKET_NAME = 'project-bucket'
GS_PROJECT_ID = 'xxxxxx'

# STATICFILES_DIRS = []

DEFAULT_FILE_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"
STATICFILES_STORAGE = "storages.backends.gcloud.GoogleCloudStorage"

STATIC_URL = 'https://storage.googleapis.com/project-bucket/static/'

# GS_DEFAULT_ACL = "publicRead"

from google.oauth2 import service_account

GS_CREDENTIALS = service_account.Credentials.from_service_account_file(os.path.join(BASE_DIR, 'db/key.json'))

When I run './manage.py collectstatic' got following error

raise exceptions.from_http_response(response)
google.api_core.exceptions.Forbidden: 403 GET https://storage.googleapis.com/storage/v1/b/project-bucket/o/admin%2Fcss%2Fautocomplete.css?projection=noAcl&prettyPrint=false: project@project.iam.gserviceaccount.com does not have storage.objects.get access to the Google Cloud Storage object.

Please help me in understanding this and give me respective solution.

Thanks in advance!

  • `403` error code means you don't have permission to do that task so check your credential or secret key or maybe something else – Ankit Tiwari Jun 15 '21 at 17:58
  • try to `print(GS_CREDENTIALS)` and check whether you are getting you key or not. – Ankit Tiwari Jun 15 '21 at 18:01
  • and always import package at top of your code because python is an interpreted language it checks line by line your code by importing packages at the top of you page python interpreter can understand your code well.check more details here https://stackoverflow.com/a/128577/14457833 – Ankit Tiwari Jun 15 '21 at 18:03
  • Allowing 'Created Storage Viewer' permission solved the problem. Thanks! – Vishal Kapale Jun 16 '21 at 10:22

0 Answers0