如何在Azure SDK for Python中过滤Blob



我想根据特定标签(如:.name.creation_date.size…(在Azure blob存储中搜索blob

我目前的方法是使用MyContainerClient.list_blobs从容器中返回所有Blob,然后搜索相应的标签。由于我的容器存储了大约800000个Blob,这需要大约20分钟的时间,这对于内容的实时视图来说是不可用的。

但我还发现了另一个ContainerClient函数:.find_blobs_by_tags(filter_expression: str),在这里我可以搜索标记符合指定条件的特定blob。

在Azure API中,他们将此filter_expression指定为:""yourtagname"='firsttag'",因此我指定了:""name"='example.jpg'"""creation_date"='2021-07-04 09:35:19+00:00'"

Azure SDK Python-ContainerClient.find_blobs_by_tag

不幸的是,我总是收到一个错误:

azure.core.exceptions.HttpResponseError: Error parsing query at or near character position 1: unexpected 'creation_time'
RequestId:63bd850b-401e-005f-745e-400d5a000000
Time:2022-03-25T15:40:22.4156367Z
ErrorCode:InvalidQueryParameterValue
queryparametername:where
queryparametervalue:'creation_time'='0529121f-7676-46c7-8a52-424664774240/0529121f-7676-46c7-8a52-424664774240.json'
reason:This query parameter value is invalid.
Content: <?xml version="1.0" encoding="utf-8"?>
<Error><Code>InvalidQueryParameterValue</Code><Message>Error parsing query at or near character position 1: unexpected &apos;creation_time&apos;
RequestId:63bd850b-401e-005f-745e-400d5a000000
Time:2022-03-25T15:40:22.4156367Z</Message><QueryParameterName>where</QueryParameterName><QueryParameterValue>&apos;creation_time&apos;=&apos;0529121f-7676-46c7-8a52-424664774240/0529121f-7676-46c7-8a52-424664774240.json&apos;</QueryParameterValue><Reason>This query parameter value is invalid.</Reason></Error>

有人有使用此Azure函数调用的经验吗?

查看github代码(在find_blobs_by_tags函数中(,它说:

:param str filter_expression:
The expression to find blobs whose tags matches the specified condition.
eg. ""yourtagname"='firsttag' and "yourtagname2"='secondtag'"

看起来你错过了转义符了?你能试着把它们包括进来吗?

最新更新