Azure Function blob trigger using reauest fail with unknown reason

현균 박 41 Reputation points
2021-03-19T01:02:26.887+00:00

Hi.

I made Azure blob trigger(using python) for run Azure Devops Pipelines.

If I run this trigger on local, it will run without any problems.

However, if I deploy the trigger as Azure portal and use it, an unknown reason will be returned.

Error

2021-03-19T00:54:58Z   [Information]   Trigger Details: MessageId: b34a8eb6-3797-4841-9a18-09a66547748f, DequeueCount: 1, InsertionTime: 2021-03-19T00:54:58.000+00:00, BlobCreated: 2021-03-19T00:54:56.000+00:00, BlobLastModified: 2021-03-19T00:54:56.000+00:00
2021-03-19T00:54:58Z   [Verbose]   Sending invocation id:1c3a7ca1-33ed-4ed1-83d2-2d38006ab462
2021-03-19T00:54:58Z   [Verbose]   Posting invocation id:1c3a7ca1-33ed-4ed1-83d2-2d38006ab462 on workerId:fa454cb8-b237-4c2f-b818-67197b8472a7
2021-03-19T00:54:58Z   [Error]   Executed 'Functions.BlobTriggerDevopsPipeline' (Failed, Id=1c3a7ca1-33ed-4ed1-83d2-2d38006ab462, Duration=79ms)
2021-03-19T00:54:59Z   [Information]   Executing 'Functions.BlobTriggerDevopsPipeline' (Reason='New blob detected: azureml-blobstore-5d7dd05e-c52c-4f52-b835-37179dea8ba8/training-data/data.txt', Id=98cc96c5-2b74-4acf-934d-89eac9ad9599)
2021-03-19T00:54:59Z   [Information]   Trigger Details: MessageId: b34a8eb6-3797-4841-9a18-09a66547748f, DequeueCount: 2, InsertionTime: 2021-03-19T00:54:58.000+00:00, BlobCreated: 2021-03-19T00:54:56.000+00:00, BlobLastModified: 2021-03-19T00:54:56.000+00:00
2021-03-19T00:54:59Z   [Verbose]   Sending invocation id:98cc96c5-2b74-4acf-934d-89eac9ad9599
2021-03-19T00:54:59Z   [Verbose]   Posting invocation id:98cc96c5-2b74-4acf-934d-89eac9ad9599 on workerId:fa454cb8-b237-4c2f-b818-67197b8472a7
2021-03-19T00:54:59Z   [Error]   Executed 'Functions.BlobTriggerDevopsPipeline' (Failed, Id=98cc96c5-2b74-4acf-934d-89eac9ad9599, Duration=22ms)
2021-03-19T00:54:59Z   [Information]   Executing 'Functions.BlobTriggerDevopsPipeline' (Reason='New blob detected: azureml-blobstore-5d7dd05e-c52c-4f52-b835-37179dea8ba8/training-data/data.txt', Id=978ce53f-2917-41c0-855c-9f33cdc54446)
2021-03-19T00:54:59Z   [Information]   Trigger Details: MessageId: b34a8eb6-3797-4841-9a18-09a66547748f, DequeueCount: 3, InsertionTime: 2021-03-19T00:54:58.000+00:00, BlobCreated: 2021-03-19T00:54:56.000+00:00, BlobLastModified: 2021-03-19T00:54:56.000+00:00

and... my codes

init.py

import logging
import base64
import requests
import azure.functions as func
# from azure.devops.connection import Connection
# from msrest.authentication import BasicAuthentication

def main(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")

    logging.info(f"start connect devops")

    pt = ':' + '[PAT CODE]'
    base64_pat = base64.b64encode(pt.encode('ascii')).decode('ascii')
    logging.info('encoding result : ' + base64_pat)

    headers = {
        'Content-Type' : 'application/json',
        'Accept' : 'application/json',
        'Authorization' : 'Basic '+ base64_pat
    }

    body = "{\r\n    \"resources\": {\r\n        \"repositories\": {\r\n            \"self\": {\r\n                \"refName\": \"master\"\r\n            }\r\n        }\r\n    }\r\n}"

    url = "https://dev.azure.com/devopscallfunc/HandsOn-CIC-TEST-Project/_apis/pipelines/3/runs?api-version=6.0-preview.1"

    response = requests.request("POST", url, headers=headers, data = body)
    logging.info(response.text.encode('utf8'))

    logging.info(f"finish connect devops")

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  }
}

Do you know why this trigger failed?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,768 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,906 Reputation points Moderator
    2021-03-19T03:52:05.68+00:00

    Hi anonymous user

    Welcome to Microsoft Q&A! Thanks for posting the question.

    I have looked into backend logs and I can see that the function app failed with the error: "ModuleNotFoundError: No module named 'requests'."
    To troubleshooting these type of error you can refer to this : https://aka.ms/functions-modulenotfound

    I will suggest you to review this article which will help you to monitor azure function. Once you have set up you can see the above error in application insights. You can also see these exceptions in the storage account that you have configured on your function aap.

    If you look into your code you will see that you are importing base 64 and requests modules (import base64 import requests). If you have any requirement where you need use any other packages that are not predefine in the functions then you need to add the names or name along with versions of the required packages to the requirements.txt file.

    Reference : https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python#package-management

    Your requirement.txt file will be:

    azure-functions  
    requests  
    base64  
    

    Hope the above helps you to resolve the issue.

    Feel free to get back to me if you need any assistance.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.