ERROR in app: Exception on / [POST] when using Flask

Viewed 2155

I have a website running https:/// using Flask. When i use the below command curl -k -X POST https:/// -d "cmd=ls" , It gives me the list of files in the server.But when i try same command multiple times and it just crashes.

I am new to Flask.I think the way i am calling /opt/svcngitls/Flask/Flask/oncall.py is having problem.

Can you pleases help on this the crashing?

Here is the configuration: 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>

And my Flask:

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

Error: curl -k -X POST https:/// -d "cmd=ls"

500 Internal Server Error Internal Server Error The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application

After i restart apache, The same command list all files in the sever with out issue

Apache Error Logs:

[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**
0 Answers
Related