skip to Main Content

I’m trying to deploy a ML model I’ve developed in Python as an Azure function.

For that, I’m following the tutorial here since I know close to nothing related with Azure functions.

After creating the local project, and upon following the instructions on step 1 of "Run the function locally":

To start the function locally, press F5 or the play icon. The Terminal
panel displays the Output from Core Tools.

When doing this, nothing happens.

According to the tutorial, I should see the URL endpoint of my HTTP-triggered function running locally as per below image from the tutorial:

enter image description here

Therefore, I’m stuck again!

Can anyone help?

EDIT:

I’m launching VsCode from Anaconda, through a virtual environment (novo).

This is the code of init.py:

import logging

import azure.functions as func

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

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.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
        )

2

Answers


  1. I followed the tutorial, and it worked for me:

    Creating Python AZ Function and Debugin

    Look like you are having a problem with something that changed location.
    How did you start? did you launch VS Code with File>New Window? When you click the "+" besides "workspace" and create a new function, did you click "create new project" and selected a folder? It seems something got lost/corrupted during that but could also be the version of your VS code. I would suggest you make sure you have the latest VS Code, the latest version of the "Azure Functions" add-on:

    Azure function Add-on for VS Code

    1. Some of the above components may be corrupted, and you need to uninstall and install them again
    2. Did you follow this steps that create the files/folders and opened it correctly:

    Steps

    Trust check

    Login or Signup to reply.
  2. Required things to be installed for running the Python Azure Function in VS Code locally are:

    1. Python Stable Version (3.x)
    2. Azure Functions Core Tools Latest Version.
    3. Latest VS Code IDE
    4. Extensions in VS Code IDE like Azurite, Python, Azure Account, Azure Functions, Azure Tools, Azure Application Insights.
    5. To run the Azure Functions locally, need Azure Storage Emulator.

    When coming to the specific errors like

    ‘C:Program Filesdotnetdotnet.exe’ is not found, ‘dotnet’ invocation will rely on the PATH environment variable

    It seems to be dotnet is not included in the System Environment Variables Path. Download .NET Core 6 SDK + Runtime and Check the installed path is added to the Environment Variables:

    • In the Command Prompt, run dotnet --version

    • Windows Search 🪟 Button > Search for Environment Variables > Open & Click 🖱️ on Environment Variables >

    enter image description here

    Below code copied from my VS Code Azure Functions Python project:

    requirements.txt :

    azure-functions
    

    local.settings.json:

    {
    "IsEncrypted": false,
    "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "python"
    }
    }
    

    host.json:

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

    function.json:

    {
    "scriptFile": "__init__.py",
    "bindings": [
    {
    "authLevel": "anonymous",
    "type": "httpTrigger",
    "direction": "in",
    "name": "req",
    "methods": [
    "get","post"
    ]
    },
    {
    "type": "http",
    "direction": "out",
    "name": "$return"
    }
    ]
    }
    
    • Make Sure the Azure Storage Emulator is running in your system so that the host errors will not occurs when running the function/trigger or you can start it manually using the below command:
    C:Program Files (x86)Microsoft SDKsAzureStorage Emulator>AzureStorageEmulator.exe start
    

    azfvscodepythoncreation

    azfvscodepythonrun

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search