簡體   English   中英

在燒瓶控制台上返回錯誤消息作為響應

[英]return error messages on flask console as response

我有一個燒瓶應用程序,可以遠程管理iptables。 當我嘗試刪除不存在的規則時,在flask控制台上出現以下錯誤:-

iptables: Bad rule (does a matching rule exist in that chain?).

而作為回應,我只會得到:

Command '['iptables', '-t', 'filter', '-s', u'<some_ip>', '-j', u'DROP', '-D', u'INPUT']' returned non-zero exit status 1

這就是我處理該異常的方式:-

except subprocess.CalledProcessError as e:
            return "\n" + str(e) + "\n"

我希望燒瓶控制台中的錯誤作為響應返回。 我該如何實現?

首先以字符串形式創建命令,然后在子流程中使用command.split()

cmd='iptables -t filter -s {}-j DROP -D INPUT'.format('127.0.0.1')

和即

subprocess.check_output(cmd.split(), sterr=subprocess.STDOUT)

第二件事:為什么要刪除不存在的規則?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM