Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cURL request refusing to connect on Flask server

I have a simple Flask server:

from flask import Flask  
app = Flask(__name__)

@app.route('/')
def hello_world():  
    return 'Hello World!'

When I run $ curl http://127.0.0.1:5000/ on the command line, I get the error

curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused

What is the problem?

like image 868
codeology Avatar asked Mar 18 '26 12:03

codeology


1 Answers

If the code snippet above is exactly the same to your code that you are trying to run then you are missing app.run() statement: Also You can specify any port number with port=<port_number> parameter in app.run()

Try this:

from flask import Flask  
app = Flask(__name__)

@app.route('/')
def hello_world():  
    return 'Hello World!'

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

and then run this script

like image 91
ShivaGaire Avatar answered Mar 20 '26 20:03

ShivaGaire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!