1

Im using a python azure function to get the trigger from azure blob using below code

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)

When a file is uploaded in the blob got the trigger. But sometimes got below error. I didn't set and header or anything to connect the blob.(Using connection string in bindings settings). Any idea what is the reason for error?

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

Bindings enter image description here

june alex
  • 244
  • 4
  • 17

2 Answers2

2

Well, when you do a Blob write operation, the ETag of Blob is reset, let us say 0x8CDA1BF0593B660. And, before it is triggered (with ETag value 0x8CDA1BF0593B660), the blob is updated by another service and it's ETag is changed to 0x8CDA1BF0593B661.

Now, when your Azure Blob triggered function app tries to read it (with ETag value 0x8CDA1BF0593B660), it is not as expected and gets this error.

This error situation is similar to Azure Blob: "The condition specified using HTTP conditional header(s) is not met" and Azure Blob Error: StorageException: The condition specified using HTTP conditional header(s) is not met

Fix for this can be (un tested), add Access => if match = * in your Blob Trigger Attribute:

enter image description here

Harshita Singh
  • 4,590
  • 1
  • 10
  • 13
  • how do i set the if match = * in blob trigger.? – june alex Mar 24 '21 at 14:31
  • binding using "bindings": [ { "name": "blobdata", "type": "blobTrigger", "direction": "in", "path": "Data/Processing/{uniqueid}.json", "connection":"connectionurl" } ] – june alex Mar 24 '21 at 14:33
  • this is what i expected. Im using KEDA to scale the object. So the file may be changed .How do i read and write the file without etag ? – june alex Mar 24 '21 at 14:43
  • updated the question with bindings. How to set if match = * in binding – june alex Mar 24 '21 at 14:47
  • https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=csharp#configuration in this link there is no way to set conditon – june alex Mar 24 '21 at 18:32
1

Hi I had the same issue.

I applied Harshita Singh suggestion, and the parameter is caught by the azure function. As shown in the image below: enter image description here

The message will keep appearing but after a while the blob is triggered, I believe the problem is with the time to generate the logs from azure. This blog also helped: http://dontcodetired.com/blog/post/Improving-Azure-Functions-Blob-Trigger-Performance-and-Reliability-Part-2-Processing-Delays-and-Missed-Blobs.

At the end my function.json is that:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "your_path/{name}",
      "connection": "storage_account",
      "Access": "=> if match = *"
    }
  ],
  "disabled": false
}
Dharman
  • 30,962
  • 25
  • 85
  • 135