admin管理员组

文章数量:1122846

I am trying to deploy a FastAPI application on Vercel, but I am having trouble getting environment variables to load. My setup works perfectly fine locally, where I use python-dotenv with load_dotenv() to load the .env file, but on Vercel, the environment variables are not being found at runtime.

Here are the steps I've taken so far:

  1. Added environment variables in the Vercel dashboard under Settings > Environment Variables.
  2. Verified that the app works locally with the same .env file using load_dotenv().
  3. Deployed the app to Vercel, but it fails to find the environment variables.
  4. Tried changing the Vercel Node.js version to 18.x (based on suggestions from other threads), but this caused my application to stop working entirely.

Additional Details:

  1. My application uses Python 3.11 and FastAPI.
  2. My environment variables include SECRET_KEY and DATABASE_URL.

Questions:

  1. Is there a specific configuration required to make Python-based apps load environment variables correctly on Vercel?
  2. Does Vercel require a particular runtime configuration to support Python 3.11 and environment variables together?
  3. Has anyone successfully run a FastAPI app on Vercel with environment variables recently?

Any guidance or examples would be greatly appreciated!

Thank you in advance for your help.

I am trying to deploy a FastAPI application on Vercel, but I am having trouble getting environment variables to load. My setup works perfectly fine locally, where I use python-dotenv with load_dotenv() to load the .env file, but on Vercel, the environment variables are not being found at runtime.

Here are the steps I've taken so far:

  1. Added environment variables in the Vercel dashboard under Settings > Environment Variables.
  2. Verified that the app works locally with the same .env file using load_dotenv().
  3. Deployed the app to Vercel, but it fails to find the environment variables.
  4. Tried changing the Vercel Node.js version to 18.x (based on suggestions from other threads), but this caused my application to stop working entirely.

Additional Details:

  1. My application uses Python 3.11 and FastAPI.
  2. My environment variables include SECRET_KEY and DATABASE_URL.

Questions:

  1. Is there a specific configuration required to make Python-based apps load environment variables correctly on Vercel?
  2. Does Vercel require a particular runtime configuration to support Python 3.11 and environment variables together?
  3. Has anyone successfully run a FastAPI app on Vercel with environment variables recently?

Any guidance or examples would be greatly appreciated!

Thank you in advance for your help.

Share Improve this question asked Nov 21, 2024 at 12:34 Anderson KAnderson K 5,5055 gold badges37 silver badges51 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

you need to use os.environ.get("< KEY >") to get the key-value in env. it is also mentioned in Vercel Documentation. it looks like versel add the env pair during the run time.

本文标签: pythonEnvironment Variables Not Loading in FastAPI App on VercelStack Overflow