Running python flask application on repl gives error - python

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

Related

Why isn't the Flask public server receiving requests?

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

how to change wsgi server to localhost?

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)

flask run command on a flask app with flask-socketio extension

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!

ipv4 networking not enabled when runnig docker

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

Python flask expose to external visible

With the help of the post Flask - configure dev server to be visible across the network, I have tried the same to make my Flask externally visible so that I can send HTTP requests from my local browser to the Flask in remote server.
Can someone please help on why its not working for me even I have opened the connections.
I started my flask in Putty [script in dev server] and tried accessing the URL from my Chrome as http://[my_sys_ip]:5000/. Chrome reports me OOPS error.
On Flask, I have made it externally visble with debug mode turned off:
if __name__ == '__main__':
app.run(host='0.0.0.0', debug = False)
From netstat, I can see its listening on 5000:
netstat -an | grep :5000
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN
When tried to send a GET request from the same dev server, I'm successful with the expected response:
python testing.py
URL called is http://0.0.0.0:5000/
Message to the user is Hello World!!!!!!!
What am I missing ?
I know this is an old question, but I figured I'll throw my 2 cents in.
From your description, it sounds like you are launching your flask application on a remote server (dev server) through PuTTY. You are then trying to access the app on your local system (localhost). The application isn't running on your local system, so that would explain the error in chrome.
Instead of going to http://[my_sys_ip]:5000, you will need to go to http://[dev_svr_ip]:5000.

Categories

Resources