I’m trying to set up an Azure Function in Python, but I’m encountering errors when running the function. Below is my function code:
import azure.functions as func
import logging
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="APIPreguntaleia")
def APIPreguntaleia(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
)
When I run the function, I get the following console error:
Executing task: .venvScriptspython -m pip install -r requirements.txt
Requirement already satisfied: azure-functions in r:fast-api.venvlibsite-packages (from -r requirements.txt (line 5)) (1.19.0)
* Terminal will be reused by tasks, press any key to close it.
* Executing task: .venvScriptsactivate ; func host start
Found Python version 3.11.9 (py).
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-05-30T19:29:34.890Z] A host error has occurred during startup operation '95a1dbe5-8264-4a29-b39a-5a6dc58447df'.
[2024-05-30T19:29:34.893Z] Microsoft.Azure.WebJobs.Script: WorkerConfig for runtime: python not found.
[2024-05-30T19:29:34.903Z] Failed to stop host instance '96a67c8f-f7a7-45fa-83c3-be938325ae8c'.
[2024-05-30T19:29:34.907Z] Microsoft.Azure.WebJobs.Host: The host has not yet started.
Value cannot be null. (Parameter 'provider')
[2024-05-30T19:29:34.915Z] Host startup operation has been canceled
* The terminal process "C:Program FilesPowerShell7pwsh.exe -Command .venvScriptsactivate ; func host start" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
I tried installing the azure-functions-worker package, but encountered another error:
PS R:Fast-API> pip install azure-functions-worker
Collecting azure-functions-worker
Using cached azure_functions_worker-1.1.9-py3-none-any.whl.metadata (7.7 kB)
Collecting grpcio~=1.33.1 (from azure-functions-worker)
Using cached grpcio-1.33.2.tar.gz (20.9 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Collecting grpcio-tools~=1.33.1 (from azure-functions-worker)
Using cached grpcio-tools-1.33.2.tar.gz (2.1 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Collecting six>=1.5.2 (from grpcio~=1.33.1->azure-functions-worker)
Using cached six-1.16.0-py2.py3-none-any.whl.metadata (1.8 kB)
Collecting protobuf<4.0dev,>=3.5.0.post1 (from grpcio-tools~=1.33.1->azure-functions-worker)
Using cached protobuf-3.20.3-py2.py3-none-any.whl.metadata (720 bytes)
Using cached azure_functions_worker-1.1.9-py3-none-any.whl (54 kB)
Using cached protobuf-3.20.3-py2.py3-none-any.whl (162 kB)
Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Building wheels for collected packages: grpcio, grpcio-tools
Building wheel for grpcio (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for grpcio (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [80 lines of output]
...
error: [WinError 2] El sistema no puede encontrar el archivo especificado
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for grpcio
Building wheel for grpcio-tools (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for grpcio-tools (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [69 lines of output]
...
grpc_tools_protoc_compiler.cpp(394): fatal error C1083: No se puede abrir el archivo incluir: 'longintrepr.h': No such file or directory
error: command 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\bin\HostX86\x64\cl.exe' failed with exit code 2
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for grpcio-tools
Failed to build grpcio grpcio-tools
ERROR: Could not build wheels for grpcio, grpcio-tools, which is required to install pyproject.toml-based projects
Environment details:
Python version: 3.11.9
Azure Functions Core Tools version: 4.0.5801
I’ve tried several solutions but nothing seems to work. How can I fix this issue?
Thanks for the help.
Sebastián Romero is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.