【发布时间】:2020-11-23 22:51:35
【问题描述】:
在 Azure 存储中设置 blob 元数据时遇到问题。我在 Spyder 中为此开发了一个脚本,所以本地 Python 非常好用。现在,我希望能够像 Azure 函数一样执行相同的脚本。但是,在设置元数据时出现以下错误:HttpResponseError: The specifed resource name contains invalid characters.
我所做的从 Spyder 到 Functions 的唯一更改是:
间谍:
def main(container_name,blob_name,metadata):
from azure.storage.blob import BlobServiceClient
# Connection string to storage account
storageconnectionstring=secretstoragestringnotforstackoverflow
# initialize clients
blobclient_from_connectionstring=BlobServiceClient.from_connection_string(storageconnectionstring)
containerclient=blobclient_from_connectionstring.get_container_client(container_name)
blob_client = containerclient.get_blob_client(blob_name)
# set metadata of container
blob_client.set_blob_metadata(metadata=metadata)
return
功能
def main(req: func.HttpRequest):
container_name = req.params.get('container_name')
blob_name = req.params.get('blob_name')
metadata_raw = req.params.get('metadata')
metadata_json = json.loads(metadata_raw)
# Connection string to storage account
storageconnectionstring=secretstoragestringnotforstackoverflow
# initialize clients
blobclient_from_connectionstring=BlobServiceClient.from_connection_string(storageconnectionstring)
containerclient=blobclient_from_connectionstring.get_container_client(container_name)
blob_client = containerclient.get_blob_client(blob_name)
# set metadata of container
blob_client.set_blob_metadata(metadata=metadata_json)
return func.HttpResponse()
函数的参数在标头中传递。问题在于元数据,而不是 container_name 或 blob_name,因为我在注释掉元数据时没有收到任何错误。此外,我尝试使用单引号或双引号以及 JSON 或字符串格式化许多变体中的元数据,但到目前为止没有运气。谁能帮我解决这个问题?
【问题讨论】:
标签: python azure azure-functions