Azure Function HTTP Trigger error 500

Jean Paul Tecson 21 Reputation points
2022-03-30T01:34:41.763+00:00

I'm trying to make a http trigger function app that will save logs as text into the azure storage and i'm currently testing on putting a simple text file into the storage account first but just by adding from azure.storage.blob import BlobServiceClient, BlobClient from azure.storage.blob import ContentSettings, ContainerClient I get error 500 adding simple variables don't affect anything and other imports.

I'm using visual studio code

This is my init.py:

from cgi import test
import logging

from azure.storage.blob import BlobServiceClient, BlobClient
from azure.storage.blob import ContentSettings, ContainerClient
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')    

    connectionstr = "my connection string"
    Container_name = "container"

    name = req.params.get('name')
    if not name:
        try:
            req_name = req.get_json()
        except ValueError:
            pass
        else:
            name = req_name.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
3,684 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 63,506 Reputation points
    2022-03-30T07:37:46.647+00:00

    @Jean Paul Tecson @Jeff Liu Thanks for reaching out. As you are using requests and azure-storage-blob module in your azure function and when there is a missing dependency, you should see the below error message in application insights that you have configured for your function app. Whenever you received 500 errors then you can always navigate to application insights logs to get more details on the actual exception in the case of 500 or any error code.
    ModuleNotFoundError: No module named 'requests'
    ModuleNotFoundError: No module named 'azure-storage'

    If you have any requirement where you need to use any other packages that are not predefined in the functions then you need to add the names or names along with versions of the required packages to the requirements.txt file. Please refer to this document for more details

    To troubleshoot these types of errors you can always refer to this document.

    Your requirement.txt file will be as below per the exception but in case if you are using any other packages then please make sure that you have defined the same.

     azure-functions  
     requests  
    azure-storage-blob  
    

    For your reference, I will suggest you to review this article which will can help you to monitor azure function. Once you have set it 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 app.

    For Community: Please refer to Azure function python document to get more familiar with the development.

    Feel free to get back to me if you still observe the issue. I will initiate the private comment so you can share your function app name so I can assist you further.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful