0

我使用python azure 函数使用以下代码从 azure blob 获取触发器

import azure.functions as func
def main(blobdata: func.InputStream):
    totalprocessingtime = time.time()
    filename=os.path.basename(blobdata.name)
    blobfilepath = str(blobdata.name).replace(str(filesystemName)+"/","")
    logging.error("blobfilepath: "+ blobfilepath)

当在 blob 中上传文件时,就会触发。但有时会低于错误。我没有设置和标题或任何东西来连接blob。(在绑定设置中使用连接字符串)。知道错误的原因是什么吗?

Executed 'Functions.blobprocessor' (Failed, Id=91e051f4-4e19-4892-91bc-aa6921579ba8, Duration=77ms)
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.timeseries2sqlprocessor
 ---> System.InvalidOperationException: Exception binding parameter 'blobdata'
 ---> Microsoft.WindowsAzure.Storage.StorageException: The condition specified using HTTP conditional header(s) is not met.
   at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
   at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.DownloadRangeToStreamAsync(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, IProgress`1 progressHandler, CancellationToken cancellationToken)
   at Microsoft.WindowsAzure.Storage.Blob.BlobReadStream.DispatchReadAsync(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Stream.CopyToAsyncInternal(Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
   at Microsoft.Azure.WebJobs.Host.Blobs.WatchableReadStream.CopyToAsyncCore(Task baseTask) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Extensions.Storage\Blobs\WatchableReadStream.cs:line 40
   at Microsoft.Azure.WebJobs.ConverterManager.<>c.<<-ctor>b__4_4>d.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\ConverterManager.cs:line 74
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Azure.WebJobs.ConverterManager.<>c__DisplayClass12_0`2.<<AddExactConverter>b__0>d.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\ConverterManager.cs:line 213
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Azure.WebJobs.ConverterManager.<>c__DisplayClass20_1`2.<<GetComposition>b__0>d.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\ConverterManager.cs:line 439
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Azure.WebJobs.IConverterManagerExtensions.<>c__DisplayClass1_0`2.<<AsTyped>b__0>d.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\IConverterManager.cs:line 52
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Azure.WebJobs.Host.Bindings.TriggerAdapterBindingProvider`2.ExactBinding`1.BindAsync(Object value, ValueBindingContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\BindingProviders\TriggerAdapterBindingProvider.cs:line 217
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.TriggerWrapper.BindAsync(Object value, ValueBindingContext context) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 496
   at Microsoft.Azure.WebJobs.Host.Triggers.TriggeredFunctionBinding`1.BindCoreAsync(ValueBindingContext context, Object value, IDictionary`2 parameters) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Triggers\TriggeredFunctionBinding.cs:line 56
Request Information
RequestID:4e02bac0-501e-006b-1e54-1b1ac2000000
RequestDate:Wed, 17 Mar 2021 17:39:10 GMT
StatusMessage:The condition specified using HTTP conditional header(s) is not met.
ErrorCode:ConditionNotMet
ErrorMessage:The condition specified using HTTP conditional header(s) is not met.
RequestId:4e02bac0-501e-006b-1e54-1b1ac2000000
Time:2021-03-17T17:39:10.6470643Z

绑定 在此处输入图像描述

4

2 回答 2

2

好吧,当您执行 Blobwrite操作时,ETagBlob 的 被重置,让我们说0x8CDA1BF0593B660。并且,在它被触发之前(使用 ETag 值0x8CDA1BF0593B660),该 blob 由另一个服务更新,并ETag更改为0x8CDA1BF0593B661.

现在,当您的 Azure Blob 触发函数应用尝试读取它(使用 ETag 值0x8CDA1BF0593B660)时,它与预期不符并出现此错误。

此错误情况类似于Azure Blob:“未满足使用 HTTP 条件标头指定的条件”Azure Blob 错误:StorageException:未满足使用 HTTP 条件标头指定的条件

可以(未经测试)对此进行修复,添加Access => if match = *您的 Blob 触发器属性:

在此处输入图像描述

于 2021-03-19T06:00:41.117 回答
0

嗨,我有同样的问题。

我应用了 Harshita Singh 的建议,并且该参数被 azure 函数捕获。如下图所示: 在此处输入图像描述

该消息将继续出现,但在触发 blob 一段时间后,我认为问题在于从 azure 生成日志的时间。这个博客也有帮助:http ://dontcodetired.com/blog/post/Improving-Azure-Functions-Blob-Trigger-Performance-and-Reliability-Part-2-Processing-Delays-and-Missed-Blobs 。

最后我的function.json是:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "your_path/{name}",
      "connection": "storage_account",
      "Access": "=> if match = *"
    }
  ],
  "disabled": false
}
于 2022-01-05T13:15:54.940 回答