Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何为Google云存储桶选择存储类别和位置_Python_Google Cloud Storage - Fatal编程技术网

Python 如何为Google云存储桶选择存储类别和位置

Python 如何为Google云存储桶选择存储类别和位置,python,google-cloud-storage,Python,Google Cloud Storage,我可以在谷歌云上创建存储桶,但我不能选择存储类{Multi-regional、regional、Nearline、Coldline}或位置{'us-west1',等等} from google.cloud import storage def CreateBucket(name): try: storageClient = storage.Client() bucket = storageClient.create_bucket(name)

我可以在谷歌云上创建存储桶,但我不能选择存储类{Multi-regional、regional、Nearline、Coldline}或位置{'us-west1',等等}

from google.cloud import storage    

def CreateBucket(name):
    try:
        storageClient = storage.Client()
        bucket = storageClient.create_bucket(name)
        print(f'Bucket {bucket.name} created.')
    except Exception as ex:
        print(f'exception!\n{ex}')


name = 'my_globally_unique_bucket_name'
CreateBucket(name)

在Python中,不显示bucket_name之外的任何参数;但是,Go、Java、Node.JS和Ruby都会显示存储类和位置选项的参数。

将代码更改为:

from google.cloud import storage

def CreateBucket(name):
        try:
            storageClient = storage.Client()
            bucket = storageClient.bucket(name)
            bucket.location = "us-west1"
            bucket.storage_class = "COLDLINE"
            bucket.create()
            print("Bucket {} created.".format(name))
        except Exception as ex:
            print("exception!\n{}".format(ex))

name = 'my_globally_unique_bucket_name'
CreateBucket(name)
您可以找到Google Cloud Client Library for Python的文档,其中显示了类“Bucket”的方法和属性