Issue
I am a newcomer to flask. I cannot access localhost:5000 or 127.0.0.1:5000 . I am using flask . I have tried many solutions but none of them worked for me. Here's the code
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return ('Hello World')
if __name__ == '__main__':
app.run()
I get this
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
when i go to localhost:5000 or 127.0.0.1:5000 , i get
127.0.0.1 refused to connect** or **localhost refused to connect
Solution
Try to run your app like this:
if __name__ == '__main__':
app.run(host='0.0.0.0',port=5000)
This also makes the server externally visible. If the IP address of the machine is 192.168.X.X
then, from the same network you can access it in 5000 port.
It could also be an issue with the firewall, in which case, do the following:
sudo ufw allow 5000
Edit:
Since you are running on Google Colab and not on your local system. The running steps would vary.
Do note that
Google Colab provides a VM(virtual machine) so we cannot access the localhost(all it does it route it to our local machine’s localhost) as we do on our local machine when running a local web server. What we can do is expose it to a public URL using ngrok. Here comes the Python library flask-ngrok.
Follow the steps here to get it running with flask-ngrok
Answered By - AzyCrw4282
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.