skip to Main Content

I have developed an azure function app. It is in Python and works perfectly fine. I first developed this in a virtual environment using pyenv on my laptop.

Now, I switched to another laptop, downloaded the function app and set a new virtual environment for this laptop. The function starts fine and the virtual environment works. The packages are installed as far as I can see.

However, when starting the function, I get the error ‘No job functions found. Try making your job classes and methods public. If you’re using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you’ve called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.)’.

I have seen others with similar issues. However, these issues were mostly in the host.json and the local.settings.json.I have not yet been able to find a solution to it, or an error in both of these files. Also, my function_app.py does not throw any errors (possibly because it is not seen…)

The first few lines of my function_app.py, where i added the @app.function_name line as per previous posts:

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.function_name("func")
@app.route(route="http_example", auth_level=func.AuthLevel.ANONYMOUS)
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

the host.json:

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

the local.settings.json:

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

It is good to know that this is another laptop, logged in with an account from another tenant. I am not sure if this may cause an issue.

Thank you in advance.

EDIT:
Screenshot of the folder structure:
folderstructure

launch.json:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Attach to Python Functions",
        "type": "debugpy",
        "request": "attach",
        "connect": {
            "host": "localhost",
            "port": 9091
        },
        "preLaunchTask": "func: host start"
    }
]

}

2

Answers


  1. Chosen as BEST ANSWER

    My problem was in the fact that I was using an old version of the Functions Core Tools. I have updated this version to version 4 with command:

    npm install -g azure-functions-core-tools@4 --unsafe-perm true
    

    Thanks to @Ikhtesam Afrin, who helped me through the comments.


  2. ‘No job functions found. Try making your job classes and methods public. If you’re using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you’ve called the registration method for the extension(s) in your startup code (e.g.builder.AddAzureStorage(), builder.AddServiceBus(),builder.AddTimers(), etc.)’.

    In order to avoid this error, please follow below steps-

    1. Use correct function code.
    import azure.functions as func
    import logging
    
    app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
    
    @app.route(route="http_trigger")
    def http_trigger(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
            )
    
    1. Ensure to use latest extension in host.json file.
    {
      "version": "2.0",
      "logging": {
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
          }
        }
      },
      "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[4.*, 5.0.0)"
      }
    }
    
    1. It is recommended to use V4 version of Azure Function core Tools. You can either install it using MSI or npm i -g azure-functions-core-tools@4 --unsafe-perm true, refer Azure Functions Core Tools Versions.

    2. Either navigate to Run -> Start debugging in vs code or use func host start command in terminal to execute your function.

    You will get the expected response.

    enter image description here

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