Can't connect to Flask web service, connection refused

前端 未结 7 2153
Happy的楠姐
Happy的楠姐 2020-12-08 18:06

I\'m trying to run a simple web server on a Raspberry Pi with Flask. When I run my Flask app, it says:

running on http://127.0.0.1:5000/

相关标签:
7条回答
  • 2020-12-08 18:38

    A reason could also be in firewall refusing incoming connections on port 5000. Try:

    sudo ufw allow 5000
    
    0 讨论(0)
  • 2020-12-08 18:38
    app.run(host='0.0.0.0',port=5000)
    

    if you run your app in this way then your server will be visible externally. Steps by Setp:

    1. Run your app by using the following command

      app.run(host='0.0.0.0',port=5000)

    2. Go to the window cmd . Type ipconfig and get the get the IPV4 adress suppose your IPV4 address is 192.168.X.X

    3. Go to the mobile browser and type the 192.168.X.X:5000

    0 讨论(0)
  • 2020-12-08 18:40

    You will have to run the development server such that it listens to requests on all interfaces and not just the local one

    Ask Flask to listen on 0.0.0.0:PORT_NUMBER

    or any other port you may choose

    0 讨论(0)
  • 2020-12-08 18:46

    when you are running the server via flask run change it to flask run --host=0.0.0.0 to connect, find the IPV4 address of the server that your script is running on. On the same network, go to http://[IPV4 address]:5000

    0 讨论(0)
  • 2020-12-08 18:56
    • Both devices must be connected to same network.
    • Use app.run(host='0.0.0.0',port=5000) and run with your own Ipv4 address like his http://[Your Ipv4 address]:5000
    • If you are connecting this with android app then don't forget to put INTERNET permission in manifest file.
    0 讨论(0)
  • 2020-12-08 18:59

    If you have debug = True inside your app.run(), then it will not be visible to other machines either. Specify host and port inside app.run() without the debug = True.

    0 讨论(0)
提交回复
热议问题