我无法从apache配置中获取环境变量。 (不要问为什么这样做,我最初没有编码)
这就是我在apache配置中所拥有的。
<Location "/var/www">
SetHandler python-program
PythonHandler mod_python.publisher
PythonOption MYSQL_PWD ###########
PythonDebug On
</Location>
这是问题代码......
#this is the problem code in question.
def index(req):
req.add_common_vars()
os.environ["MYSQL_PWD"] = req.subprocess_env["MYSQL_PWD"]
req.content_type = "text/html"
statText = getStatText()
这是我执行此操作后得到的回溯。
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1229, in _process_target
result = _execute_target(config, req, object, arg)
File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1128, in _execute_target
result = object(arg)
File "/usr/lib/python2.5/site-packages/mod_python/publisher.py", line 213, in handler
published = publish_object(req, object)
File "/usr/lib/python2.5/site-packages/mod_python/publisher.py", line 425, in publish_object
return publish_object(req,util.apply_fs_data(object, req.form, req=req))
File "/usr/lib/python2.5/site-packages/mod_python/util.py", line 554, in apply_fs_data
return object(**args)
File "/var/www/admin/Stat.py", line 299, in index
os.environ["MYSQL_PWD"] = req.subprocess_env["MYSQL_PWD"]
KeyError: 'MYSQL_PWD'
答案 0 :(得分:0)
os.environ["MYSQL_PWD"] = req.get_options()["MYSQL_PWD"]
有关详细信息,请参阅docs on PythonOption