小编Nit*_*tin的帖子

Google Cloud Storage 提供 ServiceUnavailable:503 异常后端错误

我正在尝试将文件上传到 Google Cloud Storage Bucket。在公开它的同时,我间歇性地从谷歌那里得到这个例外。此错误几乎每 20 次上传就会出现一次。 google.api_core.exceptions.ServiceUnavailable: 503 GET https://www.googleapis.com/storage/v1/b/bucket_name/o/folder_name%2FPolicy-APP-000456384.2019-05-16-023805.pdf/acl: Backend Error

我正在使用 python3 并尝试更新google-cloud-storageto的版本,1.15.0但没有帮助。


class GoogleStorageHelper:
    def __init__(self, project_name):
        self.client = storage.Client(project=project_name)

    def upload_file(self, bucket_name, file, file_name, content_type, blob_name, is_stream):
        safe_file_name = self.get_safe_filename(file_name)
        bucket = self.client.bucket(bucket_name)
        blob = bucket.blob(safe_file_name)
        if is_stream:
            blob.upload_from_string(file, content_type=content_type)
        else:
            blob.upload_from_filename(file, content_type=content_type)
        blob.make_public() // Getting Error here
        url = blob.public_url
        if isinstance(url, six.binary_type):
            url = url.decode('utf-8')
        logger.info('File uploaded, URL: {}'.format(url))
        return url

    @staticmethod
    def get_safe_filename(file_name):
        basename, extension = file_name.rsplit('.', 1) …
Run Code Online (Sandbox Code Playgroud)

google-cloud-storage google-cloud-platform

4
推荐指数
1
解决办法
2345
查看次数