1

我有以下代码作为 get_status.py

#!/usr/bin/env python
from cgi import escape
from flup.server.fcgi import WSGIServer
import commands
import subprocess

def do_get_status():
    cmd = """/usr/bin/heat --os-username admin --os-password admin --os-tenant-name admin --os-auth-url http://ipaddress:35357/v2.0/ stack-show demo_stack"""
    status, out = commands.getstatusoutput(cmd)
    return "<pre>" + str(out) + "</pre>"

def app(environ, start_response):

    # initialise and login to the website
    #test = testpost.cookie(target_url,username, password)
    qs = environ['QUERY_STRING']
    result = do_get_status()

    start_response('200 OK', [('Content-Type', 'text/html')])
    return result

WSGIServer(app).run()

但是当我做http://myserver/cgi-bin/get_status.py我得到的输出是

Unable to establish connection to http://ipaddress:35357/v2.0/tokens

该 python 脚本在 apache cgi-bin 中运行。两天前它工作得很好,但现在它突然停止工作了。如果我接受命令并在命令行上运行它,我会得到预期的结果。我什至尝试使用 python get_status.py 运行相同的代码,我得到了预期的结果。我无法理解可能是什么问题。

4

1 回答 1

0

我能够自己解决这个问题。蛮力的方法是禁用selinux。一旦我确定 selinux 是问题的原因,我通过对 selinux 设置进行更细粒度的调整以允许从 apache 执行外部连接和 cli 命令(例如 root: setsebool -P httpd_can_network_connect 1unix stackexchange post中所述)来进一步解决它

于 2015-08-12T00:31:38.350 回答