[Python] Running an Azure Function locally results in a worker error

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I created a local Azure function project on Windows using the following CLI commands from the Azure documentation:

    func init --python

    func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous"



    Running these commands results in the following Azure function being created:

    import azure.functions as func
    import datetime
    import json
    import logging

    app = func.FunctionApp()

    @app.route(route="HttpExample", auth_level=func.AuthLevel.anonymous)
    def HttpExample(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
    )


    The requirements.txt created by the Azure Function Core Tools includes only the azure-functions library.

    After starting the function with the func start command, the worker exits with the following error:

    Found Python version 3.12.0 (py).

    Azure Functions Core Tools
    Core Tools Version: 4.0.6610 Commit hash: N/A +0d55b5d7efe83d85d2b5c6e0b0a9c1b213e96256 (64-bit)
    Function Runtime Version: 4.1036.1.23224

    [2024-12-20T13:20:17.095Z] ERROR: unhandled error in functions worker: '_SixMetaPathImporter' object has no attribute '_path'
    [2024-12-20T13:20:17.127Z] Language Worker Process exited. Pid=13732.
    [2024-12-20T13:20:17.128Z] py exited with code 1 (0x1). AttributeError: '_SixMetaPathImporter' object has no attribute '_path',AttributeError: '_SixMetaPathImporter' object has no attribute '_path',AttributeError: '_SixMetaPathImporter' object has no attribute '_path'.
    [2024-12-20T13:21:15.126Z] Starting worker process failed
    [2024-12-20T13:21:15.129Z] Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out.
    [2024-12-20T13:21:15.133Z] Failed to start language worker process for runtime: python. workerId:ed1a4b3d-07d0-41f7-9116-2f60397a6748


    How can I fix this?

    What I tried:

    • I checked that the core Azure Functions Core Tools were working properly
    • I updated pip and recreated the python venv
    • I reinstalled Azure Function Core Tools
    • I checked that npm and node.js were properly installed and functioning
    • I re-did all steps from the documentation in a different directory to make sure I didn't miss anything

    Continue reading...

Compartilhe esta Página