mod_python req.subprocess_env 没有“看到” Python选项

发布于 2024-08-09 15:50:52 字数 1577 浏览 3 评论 0原文

我在从 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'

I'm having trouble getting an environmental variable out of apache config. (don't ask why it's being done this way, I didn't originally code it)

This is what I have in the apache config.

<Location "/var/www">
    SetHandler python-program
    PythonHandler mod_python.publisher
    PythonOption MYSQL_PWD ###########
    PythonDebug On
</Location>

This is the problem code...

#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()

here is the traceback I'm getting from executing this.

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十雾 2024-08-16 15:50:52
os.environ["MYSQL_PWD"] = req.get_options()["MYSQL_PWD"]

有关更多详细信息,请参阅 PythonOption 文档

os.environ["MYSQL_PWD"] = req.get_options()["MYSQL_PWD"]

See docs on PythonOption for more details

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文