ValueError:存储桶名称必须以数字或字母开头和结尾

问题描述 投票:0回答:2

我正在尝试将 SavedModel 格式的张量流模型从我的谷歌云存储桶加载到我的云函数中。我正在使用本教程:https://cloud.google.com/blog/products/ai-machine-learning/how-to-serve-deep-learning-models-using-tensorflow-2-0-with-cloud -功能

云函数编译正确。但是,当我向云功能发送 http 请求时,它会出现以下错误:

回溯(最近一次调用最后一次):

文件“/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py”,第 402 行,在 run_http_function 结果 = _function_handler.invoke_user_function(flask.request) 文件“/env/local /lib/python3.7/site-packages/google/cloud/functions/worker_v2.py”,第 268 行,invoke_user_function 返回 call_user_function(request_or_event) 文件“/env/local/lib/python3.7/site-packages/google /cloud/functions/worker_v2.py”,第 261 行,在 call_user_function 返回 self._user_function(request_or_event) 文件“/user_code/main.py”,第 29 行,在预测 download_blob('', 'firstModel/saved_model.pb', '/tmp/model/saved_model.pb') 文件“/user_code/main.py”,第 17 行,在 download_blob 存储桶 = storage_client.get_bucket(bucket_name) 文件“/env/local/lib/python3.7/site-packages” /google/cloud/storage/client.py”,第 356 行,在 get_bucket 存储桶 = self._bucket_arg_to_bucket(bucket_or_name) 文件“/env/local/lib/python3.7/site-packages/google/cloud/storage/client. py”,第 225 行,在 _bucket_arg_to_bucket bucket = Bucket(self, name=bucket_or_name) 文件“/env/local/lib/python3.7/site-packages/google/cloud/storage/bucket.py”,第 581 行,在init name = _validate_name(name) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/_helpers.py", line 67, in _validate_name raise ValueError("存储桶名称必须以数字或字母开头和结尾。”)ValueError:存储桶名称必须以数字或字母开头和结尾。

我很困惑,因为我的存储桶标题是一串大约 20 个字符长的字母,没有任何标点符号/特殊字符。

这是我正在运行的一些代码:

if model is None:
        download_blob('<terminatorbucket>', 'firstModel/saved_model.pb', '/tmp/model/saved_model.pb')
        download_blob('<terminatorbucket>', 'firstModel/assets/tokens.txt', '/tmp/model/assets/tokens.txt')
        download_blob('<terminatorbucket>', 'firstModel/variables/variables.index', '/tmp/model/variables/variables.index')
        download_blob('<terminatorbucket>', 'firstModel/variables/variables.data-00000-of-00001', '/tmp/model/variables/variables.data-00000-of-00001')
        model = tf.keras.models.load_model('/tmp/model') 


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

    blob.download_to_filename(destination_file_name)
python-3.x google-cloud-functions google-cloud-storage tensorflow2.0
2个回答
2
投票

错误消息抱怨您的存储桶名称中包含尖括号,这些尖括号不被视为数字或字母。 确保您的存储桶名称与您在 Cloud 控制台中看到的完全相同。


0
投票

我对添加尾部空格的存储桶名称有疑问...删除空格后工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.