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:
- Added environment variables in the Vercel dashboard under Settings > Environment Variables.
- Verified that the app works locally with the same .env file using load_dotenv().
- Deployed the app to Vercel, but it fails to find the environment variables.
- 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:
- My application uses Python 3.11 and FastAPI.
- My environment variables include SECRET_KEY and DATABASE_URL.
Questions:
- Is there a specific configuration required to make Python-based apps load environment variables correctly on Vercel?
- Does Vercel require a particular runtime configuration to support Python 3.11 and environment variables together?
- 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:
- Added environment variables in the Vercel dashboard under Settings > Environment Variables.
- Verified that the app works locally with the same .env file using load_dotenv().
- Deployed the app to Vercel, but it fails to find the environment variables.
- 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:
- My application uses Python 3.11 and FastAPI.
- My environment variables include SECRET_KEY and DATABASE_URL.
Questions:
- Is there a specific configuration required to make Python-based apps load environment variables correctly on Vercel?
- Does Vercel require a particular runtime configuration to support Python 3.11 and environment variables together?
- 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 badges1 Answer
Reset to default 0you 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
版权声明:本文标题:python - Environment Variables Not Loading in FastAPI App on Vercel - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310871a1934532.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论