本文介绍了谷歌云存储bucket.get_blob到已验证文件路径返回None的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够验证 bucket_name 中是否存在 finished_json_path ,但是我得到的 finished_json_blob 值是 None ,在运行此代码时...任何见解都非常感谢!

I am able to verify the existence of finished_json_path in the bucket_name, but I get finished_json_blob value of None, when running this code...Any insights really appreciated!

    bucket_name = mdata_list[0]
    org_repo = mdata_list[3]
    pull_number = mdata_list[4]
    job_name = mdata_list[5]
    build_number = mdata_list[6]
    prlogs_pull_dir = bucket_name + "/pr-logs/pull"
    prlogs_directory_dir = bucket_name + "/pr_logs/directory"
    finished_json_path = prlogs_pull_dir + "/" + org_repo + "/" + pull_number + "/" + job_name + "/" + build_number + "/" + "finished.json"
    events_json_url = prlogs_pull_dir + "/" + org_repo + "/" + pull_number + "/" + job_name + "/" + build_number + "artifacts/build-resources/events.json"



    storage_client = storage.Client()
    bucket = storage_client.get_bucket(bucket_name)
    finished_json_blob = bucket.get_blob(finished_json_path)
    finished_json = finished_json_blob.download_as_string()

我还用 bucket.blob 替换了 bucket.get_blob ,并进行了一些改进,但仍然在 .download_as_string 上崩溃了.不知道为什么在创建该对象时会从该对象获取pubsub消息,但是却找不到它.

I have also replaced bucket.get_blob with bucket.blob, with some improvement, but still crashes out on .download_as_string. Not sure why I'm getting a pubsub message from this object when it's created but then not able to find it.

google.api_core.exceptions.NotFound: 404 GET https://storage.googleapis.com/download/storage/v1/b/origin-ci-test/o/origin-ci-test%2Fpr-logs%2Fpull%2Fopenshift_release%2F12691%2Frehearse-12691-pull-ci-operator-framework-operator-marketplace-release-4.6-okd-images%2F1326467646144647168%2Ffinished.json?alt=media: No such object: origin-ci-test/origin-ci-test/pr-logs/pull/openshift_release/12691/rehearse-12691-pull-ci-operator-framework-operator-marketplace-release-4.6-okd-images/1326467646144647168/finished.json: ('Request failed with status code', 404, 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)
(myenv) bash-5.0$ gsutil cat gs://origin-ci-test/origin-ci-test/pr-logs/pull/openshift_release/12691/rehearse-12691-pull-ci-operator-framework-operator-marketplace-release-4.6-okd-images/1326467646144647168/finished.json
CommandException: No URLs matched: gs://origin-ci-test/origin-ci-test/pr-logs/pull/openshift_release/12691/rehearse-12691-pull-ci-operator-framework-operator-marketplace-release-4.6-okd-images/1326467646144647168/finished.json

推荐答案

关于该错误,可以确定您正在调用的完整路径是: origin-ci-test/origin-ci-test/pr-logs/pull/openshift_release/12691/rehearse-12691-pull-ci-operator-framework-operator-marketplace-release-4.6-okd-images/1326467646144647168/finished.json ,这似乎是存储桶被两次传递.

On the error can se that the full path you are calling is:origin-ci-test/origin-ci-test/pr-logs/pull/openshift_release/12691/rehearse-12691-pull-ci-operator-framework-operator-marketplace-release-4.6-okd-images/1326467646144647168/finished.json which seems to be that the bucket is passed twice.

问题在于,调用 get_blob 时,您已经处于存储桶中,但您又将其作为 finished_json_path

The issue is that when calling get_blob you are already on the bucket but you are passing it again as part of finished_json_path

在这里,我附加了他的代码,删除了路径的其他部分.

Here I am attaching he code removing the additional part of the path.

bucket_name = mdata_list[0]
org_repo = mdata_list[3]
pull_number = mdata_list[4]
job_name = mdata_list[5]
build_number = mdata_list[6]

prlogs_pull_dir = "/pr-logs/pull"
prlogs_directory_dir = bucket_name + "/pr_logs/directory"

finished_json_path = prlogs_pull_dir + "/" + org_repo + "/" + pull_number + "/" + job_name + "/" + build_number + "/" + "finished.json"
events_json_url = prlogs_pull_dir + "/" + org_repo + "/" + pull_number + "/" + job_name + "/" + build_number + "artifacts/build-resources/events.json"

storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
finished_json_blob = bucket.get_blob(finished_json_path)
finished_json = finished_json_blob.download_as_string()

这篇关于谷歌云存储bucket.get_blob到已验证文件路径返回None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 11:35