Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load_dotenv() on Azure Functions with Fastapi #469

Open
levalencia opened this issue Jun 28, 2023 · 0 comments
Open

load_dotenv() on Azure Functions with Fastapi #469

levalencia opened this issue Jun 28, 2023 · 0 comments

Comments

@levalencia
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant