i'm accessing environment variable in script os.environ.get
, it's throwing keyerror
. doesn't throw error python prompt. running on os x 10.11.6, , python 2.7.10.
what going on?
$ python score.py traceback (most recent call last): file "score.py", line 4, in <module> setup_logging() file "/score/log.py", line 29, in setup_logging config = get_config() file "/score/log.py", line 11, in get_config environment = os.environ.get('node_env') file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/userdict.py", line 23, in __getitem__ raise keyerror(key) keyerror: 'node_env' $ python -c "import os; os.environ.get('node_env')" $
as requested, here's source code score.py
from __future__ import print_function log import get_logger, setup_logging setup_logging() log = get_logger('score')
and here's log.py
import json import os import sys iron_worker import ironworker logbook import logger, processor, nestedsetup, stderrhandler, sysloghandler iron_io_task_id = ironworker.task_id() def get_config(): environment = os.environ.get('node_env') if environment == 'production': filename = '../config/config-production.json' elif environment == 'integration': filename = '../config/config-integration.json' else: filename = '../config/config-dev.json' open(filename) f: return json.load(f) def setup_logging(): # defines remote syslog handler # include task id, if defined app_name = 'scoreworker' if iron_io_task_id: app_name += '-' + iron_io_task_id config = get_config() default_log_handler = nestedsetup([ stderrhandler(), sysloghandler( app_name, address = (config['host'], config['port']), level = 'error', bubble = true ) ]) default_log_handler.push_application() def get_logger(name): return logger(name)
try running:
find . -name \*.pyc -delete
to delete .pyc
files.
researching problem came across this question, user experiencing same thing: .get()
seemingly raising keyerror
. in case, caused, according this accepted answer, .pyc
file contained code dict
value being accessed key (i.e., mydict['potentially_nonexistent_key']
), while traceback showing code updated .py
file .get()
used. have never heard of happening, traceback references current code .py
file, shows error raised outdated .pyc
file, seems have happened @ least once in history of python...
it long shot, worth try thought.
Comments
Post a Comment