Can't Access configparser environment variables from env.ini file in faust script (kafka streaming)
rawheel opened this issue · 1 comments
My Project is on FastAPI and the structure goes like this.
- project
- app
- kafka_layer
- faustworker.py
- core
- configs.py
- env.ini
My env.ini file goes like this
[DEFAULT]
DATABASE_URL=url_to_db
I've tried adding this code in configs.py
import configparser
config = configparser.ConfigParser()
config.read("env.ini")
I want to access environment variables in faustworker.py using this code
from app.core.configs import config
db_url = config['DEFAULT']['DATABASE_URL']
When I tried using the instance of config in faustworker.py, it returned KeyError: 'DATABASE_URL'
It works fine for me, both using stdlib and on the backport:
draft $ cat > env.ini
[DEFAULT]
DATABASE_URL=url_to_db
draft $ py -c "import configparser; config = configparser.ConfigParser(); config.read('env.ini'); print(config['DEFAULT']['DATABASE_URL'])"
url_to_db
draft $ pip-run -q configparser -- -c "import configparser; config = configparser.ConfigParser(); config.read('env.ini'); print(config['DEFAULT']['DATABASE_URL'])"
url_to_db
Note that this repo is for the backport of configparser, which you probably don't need on modern Pythons. Instead, use the built-in configparser.
Your issue is probably due to not loading the env.ini
you think you're loading, so related to your environment and not configparser.
It's also possible that there's something about how you're using kafka that's causing the underlying data not to be fully replicated to workers. You'll need to investigate deeper and maybe break down the issue in your environment more before reporting an issue here (or to python/cpython). For example, if the issue only occurs in a kafka environment, you'll want to put together a minimal kafka environment that someone else could use to replicate the issue.
Good luck.