gpt4 book ai didi

google-cloud-platform - Google Cloud Function 抛出 404 错误

转载 作者:行者123 更新时间:2023-12-05 07:15:04 30 4
gpt4 key购买 nike

我创建了一个 Cloud Function,它被设置为由 Google Cloud Storage 存储桶上的 Finalize/Create 事件触发。

我将 10k 图像转储到存储桶中,大部分图像成功运行了 Cloud Function,而有些图像抛出了以下异常,我只是对导致此错误的原因感到困惑。

错误返回 404,但当我检查存储桶时,图像在那里。有没有人有修复以下异常的经验?

出于某种原因,Cloud Function 正在检查一个不存在的目录。

它应该检查以下目录:

https://storage.googleapis.com/download/storage/v1/b/hidden-name/images%2F3683740a95fa3600d4d9a220c9e0b472.jpg

但是,它正在检查以下目录,该目录不存在(/o 文件夹不存在):

https://storage.googleapis.com/download/storage/v1/b/hidden-name/o/images%2F3683740a95fa3600d4d9a220c9e0b472.jpg

这是我遇到的异常:

Traceback (most recent call last): File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 721, in download_to_file transport, file_obj, download_url, headers, start, end, raw_download File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 645, in _do_download download.consume(transport) File "/env/local/lib/python3.7/site-packages/google/resumable_media/requests/download.py", line 153, in consume self._process_response(result) File "/env/local/lib/python3.7/site-packages/google/resumable_media/_download.py", line 171, in _process_response response, _ACCEPTABLE_STATUS_CODES, self._get_status_code File "/env/local/lib/python3.7/site-packages/google/resumable_media/_helpers.py", line 96, in require_status_code *status_codes google.resumable_media.common.InvalidResponse: ('Request failed with status code', 404, 'Expected one of', , ) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 383, in run_background_function _function_handler.invoke_user_function(event_object) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 217, in invoke_user_function return call_user_function(request_or_event) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker.py", line 214, in call_user_function event_context.Context(**request_or_event.context)) File "/user_code/main.py", line 44, in for_each_new_image create_thumb_move_to_thumbs_bucket(bucket_name,blob_name) File "/user_code/main.py", line 56, in create_thumb_move_to_thumbs_bucket blob_in_bucket.download_to_filename(download_tmp_filepath) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 761, in download_to_filename raw_download=raw_download, File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 724, in download_to_file _raise_from_invalid_response(exc) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 2161, in _raise_from_invalid_response raise exceptions.from_http_status(response.status_code, message, response=response) google.api_core.exceptions.NotFound: 404 GET https://storage.googleapis.com/download/storage/v1/b/hidden-name/o/images%2F3683740a95fa3600d4d9a220c9e0b472.jpg?alt=media: ('Request failed with status code', 404, 'Expected one of', , )

云函数入口方法:

def for_each_new_image(event, context):   
blob_name = event['name'].lower()
bucket_name = event['bucket']
create_thumb_move_to_thumbs_bucket(bucket_name,blob_name)

抛出错误的方法:

def create_thumb_move_to_thumbs_bucket(bucket_name,blob_name):     
bucket = _storage_client.get_bucket(bucket_name)
blob_in_bucket = bucket.blob(blob_name)

blob_name = blob_name.replace("ugc_images/","")
thumbnail_filename = blob_name.replace(".","-sm.")

thumbnail_tmp_filepath = '/tmp/{}'.format(thumbnail_filename)
download_tmp_filepath = '/tmp/{}'.format(blob_name)

blob_in_bucket.download_to_filename(download_tmp_filepath)

抛出错误的行:

blob_in_bucket.download_to_filename(download_tmp_filepath)

最佳答案

我遇到了同样的错误。我试图访问存储桶中不存在的文件。

关于google-cloud-platform - Google Cloud Function 抛出 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59736393/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com