Running into an error that has started after a reboot. I am testing using Azure Functions in conjunction with FastAPI based on: https://dev.to/manukanne/azure-functions-and-fastapi-14b6
Code was operating and test API call worked as expected. After a reboot of the machine and restarting VSCode I am now running into an issue when attempting to run locally.
I worked through SO: 76842742 which is slightly different setup but similar type of error being seen.
Virtual environment is running as expected and requirements.txt showing installed. Have run with verbose flag as well but no additional error messages were provided.
Current error:
Worker failed to index functions
Result: Failure Exception: ValueError: Could not find top level function app instances in function_app.py.
My function.json has the scriptFile: init.py which I thought would need to be function_app.py but the error indicates it is looking for the function_app.py regardless. I created a copy of my function_app.py and named it “__init __.py” as a potential fix but that produced the same error code.
At this point I am at a loss as to why the index function is not being found. Any thoughts around a potential solution?
Found Python version 3.11.0 (py)
Core Tools Version: 4.0.5611
VS Code: 1.88.1
function_app.py
import azure.functions as func
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
import logging
app = FastAPI()
@app.exception_handler(Exception)
async def handle_exception(request: Request, exc: Exception):
return JSONResponse(
status_code=400,
content={"message": str(exc)},
)
@app.get("/")
async def home():
return {
"info": "Try the API path for success"
}
@app.get("/v1/test/{test}")
async def get_test(
test: str,):
return {
"test": test,
}
def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
return func.AsgiMiddleware(app).handle_async(req, context)
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
],
"route": "/{*route}"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}