When debugging in VS Code, environment variables may be empty because they're not set in VS Code's environment.
- Create
.envfile in project root:
# Copy from example
cp .env.example .env- Edit
.envwith your values:
DATABASE_URL=postgresql://username:password@hostname:5432/database
ADURL=your_ad_url_here
ADU=your_ad_user_here
ADP=your_ad_password_here
REDBUS_ADG_MODEL=40- The launch.json will automatically load
.envfile (via"envFile": "${workspaceFolder}/.env")
- Open VS Code Settings (Cmd+, / Ctrl+,)
- Search for "python.envFile"
- Set it to
${workspaceFolder}/.env
Add to your shell profile (~/.zshrc or ~/.bashrc):
export DATABASE_URL="postgresql://username:password@hostname:5432/database"
export ADURL="your_value"
export ADU="your_value"
export ADP="your_value"
export REDBUS_ADG_MODEL="40"Then restart VS Code (so it picks up the new environment).
Since config.ini already has the database URL, the app will read from there even if environment variables are empty. The database connection should work.
However, ADURL, ADU, ADP are still needed for RedbusADG model. These can be:
- Set in
.envfile - Set in your shell profile
- Or passed directly in launch.json (not recommended for secrets)
Add this to your code temporarily to debug:
import os
logger.info('DATABASE_URL: %s', os.getenv('DATABASE_URL', 'NOT SET'))
logger.info('ADURL: %s', os.getenv('ADURL', 'NOT SET'))The app_server.py prioritizes:
- Environment variables (DATABASE_URL, POSTGRES_URL, DB_URL)
- Config file (config.ini) - database_url field
- PostgresDBHelper will try to read from environment as fallback
So even if environment variables are empty, the database URL from config.ini will be used.