Skip to content
Advertisement

Uploading file with python returns Request failed with status code’, 403, ‘Expected one of’,

blob.upload_from_filename(source) gives the error

raise exceptions.from_http_status(response.status_code, message, >response=response) google.api_core.exceptions.Forbidden: 403 POST >https://www.googleapis.com/upload/storage/v1/b/bucket1-newsdata->bluetechsoft/o?uploadType=multipart: (‘Request failed with status >code’, 403, ‘Expected one of’, )

I am following the example of google cloud written in python here!

 from google.cloud import storage

 def upload_blob(bucket, source, des):
    client = storage.Client.from_service_account_json('/path')
    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket)
    blob = bucket.blob(des)
    blob.upload_from_filename(source)

I used gsutil to upload files, which is working fine.
Tried to list the bucket names using the python script which is also working fine.
I have necessary permissions and GOOGLE_APPLICATION_CREDENTIALS set.

Advertisement

Answer

This whole things wasn’t working because I didn’t have permission storage admin in the service account that I am using in GCP.

Allowing storage admin to my service account solved my problem.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement