blob.upload_from_filename(source)
给出错误
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', )
我正在遵循用 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)
我使用 gsutil 上传文件,工作正常。
尝试使用 python 脚本列出存储桶名称,该脚本也工作正常。
我有必要的权限和 GOOGLE_APPLICATION_CREDENTIALS 设置。
最佳答案
这一切都不起作用,因为我在 GCP 中使用的服务帐户中没有 权限 storage admin
。
允许 storage admin
到我的服务帐户解决了我的问题。
关于python - 使用 python 上传文件返回 Request failed with status code', 403, 'Expected one of' , <HTTPStatus.OK : 200>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56280219/