0

I wrote this small piece of code:

from flask import Flask
from flask_restful import Resource, Api
import subprocess

app = Flask(__name__)
api = Api(app)

class SlackReport(Resource):
    def get(self):

        subprocess.Popen(['python', 'ingestion_ice3_check.py'])

        return 'Request submitted'

api.add_resource(SlackReport, '/slackReport')

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

If I execute:

curl --ipv4 http://127.0.0.1:5000/slackReport

the server sends the response but if I execute the same command from another machine in the same LAN I receive a 'connection refused' message

$ curl -X GET http://10.113.12.20:5000/slackReport
curl: (7) Failed to connect to 10.113.12.20 port 5000: Connection refused

If I request the resource from localhost I can see the request from the debug console of the server

127.0.0.1 - - [28/Sep/2017 18:15:02] "GET /slackReport HTTP/1.1" 200 -

However if I request the same resource from a remote machine I can see the packet on the port but the flask server doesn't receive anything.

$ sudo tcpdump -i ens192 port 5000
18:17:53.132514 IP 10.113.12.25.37096 > tl020dash.commplex-main: Flags [S], seq 3147843104, win 14600, options [mss 1460,sackOK,TS val 822032144 ecr 0,nop,wscale 7], length 0

This is the output of netstat command

sudo netstat -tnlp | grep :5000
tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      21872/python
Davide
  • 75
  • 7
  • 1
    Possible duplicate of [Flask - configure dev server to be visible across the network](https://stackoverflow.com/questions/7023052/flask-configure-dev-server-to-be-visible-across-the-network) – Jonas Schäfer Sep 28 '17 at 16:40

1 Answers1

0

Your are running your service on localhost (127.0.0.1) so only your computer has access to it. If you want to run that Flask service so other stuff on your network can access it you can set some keyword args when you run your app. You might need to run this as an elevated user so it can bind to that network port (10.113.12.20:5000).

if __name__ == '__main__':
    app.run(debug=True, host='10.113.12.20', port=5000)
Kyle
  • 1,056
  • 5
  • 15