【问题标题】:404 Error using compose for Google Cloud Storage in Google Cloud Function在 Google Cloud Function 中为 Google Cloud Storage 使用 compose 时出现 404 错误
【发布时间】:2021-01-22 20:01:54
【问题描述】:

我有几个文件要上传到 Google Cloud Storage,然后使用 compose 进行合并。我能够上传文件,但无法让撰写工作。我最初用 Nodejs 尝试它并得到奇怪的错误,现在尝试在用 python 编写的云函数中使用 compose。这是我正在使用的代码:

from google.cloud import storage

def compose_file(event, context):
    bucket_name = 'bucket-name-appspot.com'
    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)

    blob1 = bucket.blob('composettest/compose1.txt')
    blob2 = bucket.blob('composettest/compose2.txt')

    sources = [blob1, blob2]
    destination_blob_name = 'compose3.txt'
    print(blob1)
    print(blob2)

    destination = bucket.blob(destination_blob_name)
    print(destination)
    destination.content_type = "text/plain"
    destination.compose(sources)
    return destination

这是我不断遇到的错误。我知道该文件存在,因为我可以将其打印为 blob。有任何想法吗?是否可能存在某种权限错误?我怀疑是不是因为我可以创建和下载文件没有问题。我只是无法让 compose 与 python 或 nodejs 客户端库一起工作。

  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 449, in run_background_function
    _function_handler.invoke_user_function(event_object)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 268, in invoke_user_function
    return call_user_function(request_or_event)
  File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 265, in call_user_function
    event_context.Context(**request_or_event.context))
  File "/user_code/main.py", line 26, in compose_file
    destination.compose(sources)
  File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 3070, in compose
    retry=retry,
  File "/env/local/lib/python3.7/site-packages/google/cloud/storage/_http.py", line 63, in api_request
    return call()
  File "/env/local/lib/python3.7/site-packages/google/cloud/_http.py", line 438, in api_request
    raise exceptions.from_http_response(response)
google.api_core.exceptions.NotFound: 404 POST https://storage.googleapis.com/storage/v1/b/bucket-name-appspot.com/o/compose3.txt/compose?prettyPrint=false: Not Found

【问题讨论】:

    标签: python google-cloud-functions google-cloud-storage


    【解决方案1】:

    您不能在新文件中撰写。你拿一个文件,然后用另一个文件组成它。在您的情况下,您首先在 GCS 中创建一个空的 compose3.txt,然后您可以创建您的命令。或者,您使用 compose1 作为目标,仅使用 compose2 作为源,并且两者都组合在一起。

    【讨论】:

      【解决方案2】:

      您似乎指定了一个不存在的存储桶:

      % gsutil ls gs://bucket-name-appspot.com
      BucketNotFoundException: 404 gs://bucket-name-appspot.com bucket does not exist.
      

      【讨论】:

      • 存储桶确实存在。我刚刚更改了发布此代码的名称。我可以抓取存储桶中的文件没问题。只是无法组合它们。
      猜你喜欢
      • 1970-01-01
      • 2019-02-14
      • 2014-02-28
      • 2021-03-22
      • 1970-01-01
      • 2021-03-13
      • 2020-10-22
      • 1970-01-01
      • 2021-06-18
      相关资源
      最近更新 更多