Error when starting a basic azure function app while following Microsoft documentation

Das Gupta, Abhijeet 100 Reputation points
2024-06-25T12:24:50.7+00:00

I'm following the documentation below to create a basic function using the CLI

https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-python?tabs=windows%2Cbash%2Cazure-cli%2Cbrowser

When starting function app from the documentation example, I'm seeing the following error

[2024-06-25T12:12:35.599Z]   File "/afh/projects/abhijeet-project/azure-functions/demo/function_app.py", line 8, in <module>
[2024-06-25T12:12:35.599Z]     @app.route(route="HttpExample", auth_level=func.AuthLevel.Anonymous)
[2024-06-25T12:12:35.599Z]   File "/usr/local/lib/python3.10/enum.py", line 437, in __getattr__
[2024-06-25T12:12:35.599Z]     raise AttributeError(name) from None
[2024-06-25T12:12:35.599Z] .
[2024-06-25T12:12:36.846Z] 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.). 

Can anyone guide how to fix this error? I have not made any changes to the artifacts crated when invoking a function app project. I'm running this code on compute instance created in azure ai studio. TIA.

Here is the full log

vscode ➜ .../code/azure-functions/demo $ func start
Found Python version 3.10.13 (python3).

Azure Functions Core Tools
Core Tools Version:       4.0.5801 Commit hash: N/A +5ac2f09758b98257e728dd1b5576ce5ea9ef68ff (64-bit)
Function Runtime Version: 4.34.1.22669

[2024-06-25T12:12:35.594Z] Worker failed to index functions
[2024-06-25T12:12:35.596Z] Result: Failure
[2024-06-25T12:12:35.596Z] Exception: AttributeError: Anonymous
[2024-06-25T12:12:35.597Z] Stack:   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 413, in _handle__functions_metadata_request
[2024-06-25T12:12:35.597Z]     self.load_function_metadata(
[2024-06-25T12:12:35.597Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 393, in load_function_metadata
[2024-06-25T12:12:35.597Z]     self.index_functions(function_path, function_app_directory)) \
[2024-06-25T12:12:35.597Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py", line 765, in index_functions
[2024-06-25T12:12:35.597Z]     indexed_functions = loader.index_function_app(function_path)
[2024-06-25T12:12:35.597Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call
[2024-06-25T12:12:35.597Z]     return func(*args, **kwargs)
[2024-06-25T12:12:35.597Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.10/LINUX/X64/azure_functions_worker/loader.py", line 238, in index_function_app
[2024-06-25T12:12:35.597Z]     imported_module = importlib.import_module(module_name)
[2024-06-25T12:12:35.598Z]   File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module
[2024-06-25T12:12:35.598Z]     return _bootstrap._gcd_import(name[level:], package, level)
[2024-06-25T12:12:35.598Z]   File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
[2024-06-25T12:12:35.598Z]   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
[2024-06-25T12:12:35.598Z]   File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
[2024-06-25T12:12:35.598Z]   File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
[2024-06-25T12:12:35.598Z]   File "<frozen importlib._bootstrap_external>", line 883, in exec_module
[2024-06-25T12:12:35.598Z]   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[2024-06-25T12:12:35.599Z]   File "/afh/projects/abhijeet-project/code/azure-functions/demo/function_app.py", line 8, in <module>
[2024-06-25T12:12:35.599Z]     @app.route(route="HttpExample", auth_level=func.AuthLevel.Anonymous)
[2024-06-25T12:12:35.599Z]   File "/usr/local/lib/python3.10/enum.py", line 437, in __getattr__
[2024-06-25T12:12:35.599Z]     raise AttributeError(name) from None
[2024-06-25T12:12:35.599Z] .
[2024-06-25T12:12:36.846Z] 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.).
For detailed output, run func with --verbose flag.
[2024-06-25T12:12:41.718Z] Host lock lease acquired by instance ID '000000000000000000000000E2AC0C59'.
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,609 questions
0 comments No comments
{count} votes

Accepted answer
  1. Luis Arias 5,901 Reputation points
    2024-06-25T20:18:54.8733333+00:00

    Hi Das Gupta, Abhijeet,

    I had had this error before and I spent a lot of time but here is the solution , if you check the message is:

    [2024-06-25T12:12:35.596Z] Exception: AttributeError: Anonymous

    You need to update on your function_app.py from lower case to upper case the "ANONYMOUS" word.

    import azure.functions as func
    import datetime
    import json
    import logging
    
    app = func.FunctionApp()
    #Here be sure ANONYMOUS is on upper case.
    @app.route(route="HttpExample", auth_level=func.AuthLevel.ANONYMOUS)
    
    
    

    Additional reference:

    It already exist an issue to be fixed on the repository of azure function core tools regarding to this problem. https://github.com/Azure/azure-functions-core-tools/issues/3651

    If the information helped address your question, please Accept the answer.

    Luis


0 additional answers

Sort by: Most helpful