Python 创建错误条件:google.api_core.exceptions.NotFound:404未找到:URI

Python 创建错误条件:google.api_core.exceptions.NotFound:404未找到:URI,python,google-bigquery,Python,Google Bigquery,我想知道,如果在云存储中找不到csv文件,是否可以设置条件,终止脚本(例如打印) 因为我不知道csv会出现,所以我做了一个目录级测试,它成功了 def blob_exists(): client = storage.Client() bucket = client.get_bucket('bucket_name') bb = bucket.list_blobs(prefix='test_directory') for resource in bb:

我想知道,如果在云存储中找不到csv文件,是否可以设置条件,终止脚本(例如打印)


因为我不知道csv会出现,所以我做了一个目录级测试,它成功了

def blob_exists():
    client = storage.Client()
    bucket = client.get_bucket('bucket_name')
    bb = bucket.list_blobs(prefix='test_directory')
    for resource in bb:
        print(resource.name)
        blob = bucket.blob(resource.name)
        return blob.exists()

a = blob_exists()

if a is True:
    print("OK")
else:
    print("Not found")

也许这个答案会有帮助-@PriyaAgarwal这是相关的,但由于我不知道csv的确切名称,我可以在目录级别进行验证吗?或者是否有任何方法可以捕获即将到来的csv的名称?
def blob_exists():
    client = storage.Client()
    bucket = client.get_bucket('bucket_name')
    bb = bucket.list_blobs(prefix='test_directory')
    for resource in bb:
        print(resource.name)
        blob = bucket.blob(resource.name)
        return blob.exists()

a = blob_exists()

if a is True:
    print("OK")
else:
    print("Not found")