Executing a python script using Flask [duplicate]












-4
















This question already has an answer here:




  • Flask view raises TypeError: 'bool' object is not callable

    1 answer




I trying to executing a Python script through Flask.



I wrote below python code to execute another python script.



from flask import Flask
import subprocess

app = Flask(__name__)

@app.route("/")
def home():
subprocess.call("/home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
#return "Hello, World!"

if __name__ == "__main__":
app.run(debug=True)


But unfortunately when I run above python code and check the 127.0.0.1:5000 It's giving this error in browser :



TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.


Any solution?



My ultimate goal is to open a python script via HTML page's Button.










share|improve this question













marked as duplicate by davidism flask
Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 '18 at 13:29


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    -4
















    This question already has an answer here:




    • Flask view raises TypeError: 'bool' object is not callable

      1 answer




    I trying to executing a Python script through Flask.



    I wrote below python code to execute another python script.



    from flask import Flask
    import subprocess

    app = Flask(__name__)

    @app.route("/")
    def home():
    subprocess.call("/home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
    #return "Hello, World!"

    if __name__ == "__main__":
    app.run(debug=True)


    But unfortunately when I run above python code and check the 127.0.0.1:5000 It's giving this error in browser :



    TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.


    Any solution?



    My ultimate goal is to open a python script via HTML page's Button.










    share|improve this question













    marked as duplicate by davidism flask
    Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 21 '18 at 13:29


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      -4












      -4








      -4









      This question already has an answer here:




      • Flask view raises TypeError: 'bool' object is not callable

        1 answer




      I trying to executing a Python script through Flask.



      I wrote below python code to execute another python script.



      from flask import Flask
      import subprocess

      app = Flask(__name__)

      @app.route("/")
      def home():
      subprocess.call("/home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
      #return "Hello, World!"

      if __name__ == "__main__":
      app.run(debug=True)


      But unfortunately when I run above python code and check the 127.0.0.1:5000 It's giving this error in browser :



      TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.


      Any solution?



      My ultimate goal is to open a python script via HTML page's Button.










      share|improve this question















      This question already has an answer here:




      • Flask view raises TypeError: 'bool' object is not callable

        1 answer




      I trying to executing a Python script through Flask.



      I wrote below python code to execute another python script.



      from flask import Flask
      import subprocess

      app = Flask(__name__)

      @app.route("/")
      def home():
      subprocess.call("/home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
      #return "Hello, World!"

      if __name__ == "__main__":
      app.run(debug=True)


      But unfortunately when I run above python code and check the 127.0.0.1:5000 It's giving this error in browser :



      TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.


      Any solution?



      My ultimate goal is to open a python script via HTML page's Button.





      This question already has an answer here:




      • Flask view raises TypeError: 'bool' object is not callable

        1 answer








      python flask






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 6:45









      dishcodedishcode

      86




      86




      marked as duplicate by davidism flask
      Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 21 '18 at 13:29


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by davidism flask
      Users with the  flask badge can single-handedly close flask questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 21 '18 at 13:29


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0














          As a response, you have to return from the function. so you can do like this



          from flask import Flask
          import subprocess

          app = Flask(__name__)

          @app.route("/")
          def home():
          subprocess.call("python /home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
          return "ok"
          if __name__ == "__main__":
          app.run(debug=True)





          share|improve this answer


























          • any idea how to run above python script using html Button?

            – dishcode
            Nov 21 '18 at 7:00











          • You can make ajax call from javascript

            – Ram
            Nov 21 '18 at 7:09


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          As a response, you have to return from the function. so you can do like this



          from flask import Flask
          import subprocess

          app = Flask(__name__)

          @app.route("/")
          def home():
          subprocess.call("python /home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
          return "ok"
          if __name__ == "__main__":
          app.run(debug=True)





          share|improve this answer


























          • any idea how to run above python script using html Button?

            – dishcode
            Nov 21 '18 at 7:00











          • You can make ajax call from javascript

            – Ram
            Nov 21 '18 at 7:09
















          0














          As a response, you have to return from the function. so you can do like this



          from flask import Flask
          import subprocess

          app = Flask(__name__)

          @app.route("/")
          def home():
          subprocess.call("python /home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
          return "ok"
          if __name__ == "__main__":
          app.run(debug=True)





          share|improve this answer


























          • any idea how to run above python script using html Button?

            – dishcode
            Nov 21 '18 at 7:00











          • You can make ajax call from javascript

            – Ram
            Nov 21 '18 at 7:09














          0












          0








          0







          As a response, you have to return from the function. so you can do like this



          from flask import Flask
          import subprocess

          app = Flask(__name__)

          @app.route("/")
          def home():
          subprocess.call("python /home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
          return "ok"
          if __name__ == "__main__":
          app.run(debug=True)





          share|improve this answer















          As a response, you have to return from the function. so you can do like this



          from flask import Flask
          import subprocess

          app = Flask(__name__)

          @app.route("/")
          def home():
          subprocess.call("python /home/tech/Downloads/labelme-master/labelme/main.py 1", shell=True)
          return "ok"
          if __name__ == "__main__":
          app.run(debug=True)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 '18 at 7:05

























          answered Nov 21 '18 at 6:51









          RamRam

          385112




          385112













          • any idea how to run above python script using html Button?

            – dishcode
            Nov 21 '18 at 7:00











          • You can make ajax call from javascript

            – Ram
            Nov 21 '18 at 7:09



















          • any idea how to run above python script using html Button?

            – dishcode
            Nov 21 '18 at 7:00











          • You can make ajax call from javascript

            – Ram
            Nov 21 '18 at 7:09

















          any idea how to run above python script using html Button?

          – dishcode
          Nov 21 '18 at 7:00





          any idea how to run above python script using html Button?

          – dishcode
          Nov 21 '18 at 7:00













          You can make ajax call from javascript

          – Ram
          Nov 21 '18 at 7:09





          You can make ajax call from javascript

          – Ram
          Nov 21 '18 at 7:09





          Popular posts from this blog

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?