KEMBAR78
load_dotenv() on Azure Functions with Fastapi · Issue #469 · theskumar/python-dotenv · GitHub
Skip to content

load_dotenv() on Azure Functions with Fastapi #469

@levalencia

Description

@levalencia

I have a very weird issue and it only happens when I add the load_dotenv() line.

Environment:
Azure function locally with Fast API

References:

  1. Create an Azure Function locally
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs-code?tabs=nodejs#debugging-functions-locally
  2. Setup FAST API with Azure Functions
    https://github.com/Azure-Samples/fastapi-on-azure-functions/tree/main

Code:


[import logging
import azure.functions as func
import os
import openai
from FastAPIApp import app  # Main API application
from dotenv import load_dotenv

load_dotenv()

@app.get("/sample")
async def index():
    return {
        "info": "Try /hello/Shivani for parameterized route.",
    }


@app.get("/hello/{name}")
async def get_name(name: str):
    return {
        "name": name,
    }


async def main(req: func.HttpRequest, context: func.Context) -> func.](url)HttpResponse:
    return await func.AsgiMiddleware(app).handle_async(req, context)

Without load_dotenv() the code works perfect, any idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions