У меня есть веб-сайт с https: /// с использованием Flask.Когда я использую приведенную ниже команду curl -k -X POST https: /// -d "cmd = ls", это дает мне список файлов на сервере. Но когда я пробую одну и ту же команду несколько рази он просто падает.
Я новичок в Flask. Я думаю, что при вызове /opt/svcngitls/Flask/Flask/oncall.py возникают проблемы.
Можете ли вы помочь, пожалуйстана этот сбой?
Вот конфигурация: cat /etc/httpd/conf.d/oncallproxy.conf
ServerName
#Log Setup
CustomLog /var/log/httpd/access_oncall.log combined
ErrorLog /var/log/httpd/error_oncall.log
#CustomLog /opt/svcngitls/access_oncall.log combined
#ErrorLog /opt/svcngitls/error_oncall.log
LoadModule wsgi_module /usr/lib64/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
WSGIScriptAlias / /opt/svcngitls/Flask/Flask/oncallwsgi.wsgi
<Location />
Options -Indexes +FollowSymLinks
require all granted
</Location>
<Directory /opt/svcngitls/Flask/>
Options -Indexes +FollowSymLinks
require all granted
</Directory>
И мой настой:
cat /opt / svcngitls / Flask / Flask / oncall.py
import sys
from subprocess import Popen, PIPE, STDOUT, CalledProcessError
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def oncall():
if request.method == 'POST':
path = Popen("find /opt/svcngitls/oncall -type d -printf \":%p\"", stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)
(output, err) = path.communicate()
os.environ['PATH'] += ':' + output
cmd = str(request.get_data()).split('=')[1]
process = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)
(result, stderr) = process.communicate()
if result:
return result
else:
return stderr
elif request.method == 'GET':
return "Test mehthod for POST \n"
cat /opt/svcngitls/Flask/Flask/oncallwsgi.wsgi
import sys
sys.path.insert(0,"/opt/svcngitls/Flask/")
from Flask import app as application
cat / opt / svcngitls / Flask /Flask / init.py
if name == "main":
app.run()
Ошибка: curl -k -X POST https: /// -d "cmd = ls"
500 Внутренняя ошибка сервераВнутренняя ошибка сервера Сервер обнаружил внутреннюю ошибку и не смог выполнить ваш запрос.Либо сервер перегружен, либо в приложении произошла ошибка
После перезапуска apache та же команда выводит список всех файлов на сервере без проблемы
Журналы ошибок Apache:
[Wed Jul 03 05:35:34.947542 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] [2019-07-03 05:35:34,946] **ERROR in app: Exception on / [POST]**
[Wed Jul 03 05:35:34.947581 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] Traceback (most recent call last):
[Wed Jul 03 05:35:34.947586 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 2311, in wsgi_app
[Wed Jul 03 05:35:34.947589 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] response = self.full_dispatch_request()
[Wed Jul 03 05:35:34.947592 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
[Wed Jul 03 05:35:34.947595 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] rv = self.handle_user_exception(e)
[Wed Jul 03 05:35:34.947597 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1737, in handle_user_exception
[Wed Jul 03 05:35:34.947614 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] reraise(exc_type, exc_value, tb)
[Wed Jul 03 05:35:34.947616 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
[Wed Jul 03 05:35:34.947621 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] rv = self.dispatch_request()
[Wed Jul 03 05:35:34.947624 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/site-packages/flask/app.py", line 1818, in dispatch_request
[Wed Jul 03 05:35:34.947626 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] return self.view_functions[rule.endpoint](**req.view_args)
[Wed Jul 03 05:35:34.947629 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/opt/svcngitls/Flask/Flask/oncall.py", line 15, in oncall
[Wed Jul 03 05:35:34.947631 2019] **[wsgi:error] [pid 9133] [client 172.30.88.135:48246] process = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True, close_fds=True)**
[Wed Jul 03 05:35:34.947633 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__
[Wed Jul 03 05:35:34.947636 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] errread, errwrite)
[Wed Jul 03 05:35:34.947638 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_child
[Wed Jul 03 05:35:34.947641 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] raise child_exception
[Wed Jul 03 05:35:34.947643 2019] [wsgi:error] [pid 9133] [client 172.30.88.135:48246] **OSError: [Errno 7] Argument list too long**