I have a very simple flask application that integrates flask-socketio, and I am trying to run my server using the flask run command on my terminal. I have read the documentation and this should do the job, however the output is the following, and I cannot reach my server on 127.0.0.1:5000
and here is my code:
I would really appreciate any help :)
the problem mainly was because I was using the latest version of flask (flask 1.0) if i revert back to flask 0.12.2 running the server using flask run will work as expected.
You can use the following code snippet to host your falsk app on localhost with port number as 5000 at the end of your code.
app.run(host='127.0.0.1', port=5000)
I hope, it helps!
Related
I am trying to set up a server on a windows 10 machine, using Python and Flask, but it is not responding to external requests.
This is my server.py file:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def index():
return "Hi there"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
When running, it says:
* Running on all addresses (0.0.0.0)
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://127.0.0.1:5000
* Running on http://195.XX.XXX.XXX:5000 (Press CTRL+C to quit)
Indeed, if I try to access it from that machine, using 127.0.0.1:5000 or 195.XX.XXX.XXX:5000, it works correctly.
However, when trying to access it from another machine, (using Chrome if that can be an issue), it just loads indefinitely, then says no data received, ERR_EMPTY_RESPONSE.
What is wrong with this? I've followed steps on the documentation so I don't get what could be wrong.
I also disabled firewall entirely on the windows 10 machine.
How you're running matters. If it's via
python server.py
then the app.run() will execute, and the server will bind to 0.0.0.0
But if you're running via some variant of
FLASK_APP=server.py flask run
then app.run() won't execute, and the server will bind to 127.0.0.1
In that case, adding --host=0.0.0.0 should fix things (unless you're having a firewall issue).
I am running a python flask application in replit and when it try to access the url, i am getting the following message
Hmmmm.... We Couldn't Reach Your Repl Make sure your repl has a port open and is ready to receive HTTP traffic.
How to solve this error
Possibly you're running the flask server on a used port.
Try to set a different port:
app.run(host='0.0.0.0', port=8080)
or
flask run --host=0.0.0.0 --port=8080
world.
I am deploying a flask app and when I run the application and run.py, it runs on the http:\\0.0.0.:9999 but I want to run it on my localhost. Where and how do I change this?
Attached is the terminal output
run application terminal output
thanks.
you change it at the app.run line:
app.run(host="127.0.0.1", port=9999)
I have a remote machine at my workplace, when we developers run server/ or docker containers. everything was working fine but a while back somethign went wrong.
if I run the python flask app
from app import app
app.run(host='0.0.0.0', port=5050)
i get message
* Running on http://0.0.0.0:5050/
and I am able to access the above from my local machine using the remote server machine ip:5050 but if I run docker container docker run -itd <conta_image_name> -p 80:90 --add-host=localdomain.com:machine_ip_address i get error message saying IPv4 forwarding is disabled. Networking will not work.
Now this issue is in production so I really need someone to throw up some light, what might be wrong or let me know what more info I need to put.
I have fixed this issue myself following this: https://success.docker.com/article/ipv4-forwarding
Another solution is..
Try adding -net=host along with docker run command
https://medium.com/#gchandra/docker-ipv4-forwarding-is-disabled-8499ce59231e
I am trying to do
http://containertutorials.com/docker-compose/flask-simple-app.html
I have copied the tutorial verbatim, except I changed
From flask import Flask
to
from flask import Flask
I can built it just fine. I can start it and get the following when I run docker ps from the command line
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
291c8dfe5ddb whatever:latest "python app.py" About a minute ago Up About a minute 0.0.0.0:5000->5000/tcp sick_wozniak
I am building this on OSX
I have tried the following
Looking at this post Deploying a minimal flask app in docker - server connection issues
Running $ python app.py to make sure it works without docker
Creating a django project and a dockerfile for that project. Then build, run and access.
So I am confident that docker is working and flask is working independently of each other, but I cannot get them to work together.
If on Linux, then http://localhost:5000 should work seeing as the container is both running and listening on port 5000.
Otherwise, you would be using Docker Machine, and so you need to get the IP of the docker virtual machine using docker-machine ip. On OSX, for example
$ open http://$(docker-machine ip default):5000