Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.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
Google app engine 是否需要旧版云存储权限?_Google App Engine_Google Cloud Storage - Fatal编程技术网

Google app engine 是否需要旧版云存储权限?

Google app engine 是否需要旧版云存储权限?,google-app-engine,google-cloud-storage,Google App Engine,Google Cloud Storage,我的困惑是为什么我需要包括“遗留”云存储角色。我更喜欢避免说“遗产”的东西,因为听起来它们总有一天会被弃用的。 我做错了吗 这是我的案例: 我正在使用appengine项目中的服务帐户访问另一个项目中云存储的文件。我正在使用Google Python客户端访问数据 我已分配角色: Storage Object Creator Storage Object Viewer 但是,当我尝试访问文件时,会出现一个错误: <service account> does not have sto

我的困惑是为什么我需要包括“遗留”云存储角色。我更喜欢避免说“遗产”的东西,因为听起来它们总有一天会被弃用的。 我做错了吗

这是我的案例:

我正在使用appengine项目中的服务帐户访问另一个项目中云存储的文件。我正在使用Google Python客户端访问数据

我已分配角色:

Storage Object Creator
Storage Object Viewer
但是,当我尝试访问文件时,会出现一个错误:

<service account> does not have storage.buckets.get access
代码如下:

def download_blob(bucket_name, source_blob_name, destination_file_name):
    """Downloads a blob from the bucket."""
    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.blob(source_blob_name)
    blob.download_to_filename(destination_file_name)

    print('Blob {} downloaded to {}.'.format(
          source_blob_name,
          destination_file_name))

def upload_blob(bucket_name, source_file_name, destination_blob_name):
    """Uploads a file to the bucket."""
    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.blob(destination_blob_name)
    blob.upload_from_filename(source_file_name)

    print('File {} uploaded to {}.'.format(
          source_file_name,
          destination_blob_name))
谢谢
Rob

W.r.t在您的代码中,我添加了以下附加注释:

def download_blob(bucket_name, source_blob_name, 
destination_file_name):
    """Downloads a blob from the bucket."""
    """The following .get_bucket() requires storage.buckets.get permission."""
    bucket = storage_client.get_bucket(bucket_name)
    """The following doesn't"""
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(source_blob_name)
    blob.download_to_filename(destination_file_name)

    print('Blob {} downloaded to {}.'.format(
          source_blob_name,
          destination_file_name))
要重新迭代:

storage\u client.get\u bucket(bucket\u name)
需要storage.bucket.get的权限,因为它正在执行bucket元数据get请求

storage\u cilent.bucket(bucket\u name)
不需要此权限,因为它不执行GET请求,只使用
bucket\u name
定义的名称创建一个bucket对象

对于上载到bypass storage.Bucket.get问题:

from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.upload_from_filename(source_file_name)

你好,罗布,你能提供你正在使用的代码吗?@FrankNatividad补充道。谢谢。这对我来说似乎完全陌生;在这两种情况下,我都是从同一个桶中读取数据,所以我不明白为什么它不能与get_桶一起工作。但是谢谢,谢谢你的反馈。我想更好地回答这个问题,让你明白
get_bucket
对bucket元数据资源执行get请求。如果不想这样做,只下载文件。因此,您可以使用
bucket
创建一个包含名称的bucket引用,但不能对bucket元数据执行GET请求。@frank natividad我有一个类似的问题,这并不能向我解释。如果我给服务帐户Storage Legacy Bucket Reader和Storage Legacy Bucket Writer角色,我们的代码将按预期写入,但如果我给它Storage Object Creator角色,它将失败,因为
没有Storage.Bucket.get访问
。难道没有一个非遗留的、非管理员的角色可以写吗?Python客户机库有一种方法可以初始化一个Bucket实例,可以从GCS请求元数据,也可以不请求元数据。w、 r.t从GCS请求元数据(
storage.get_bucket()
)如果从GCS执行元数据请求,则需要storage.bucket.get。w、 r.t未从GCS请求元数据(
storage.bucket()
)。该方法只初始化bucket的实例,不请求元数据。这允许您跳过需要权限
storage.bucket.get
,因为没有检索到元数据。@FrankNatividad我不想绕过元数据请求。我要求一个非遗留的,非管理员的角色,可以写。在我看来,具有Storage Object Creator权限的服务帐户无法写入的错误。
from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.upload_from_filename(source_file_name)