codeology
codeology

Reputation: 357

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?

Upvotes: 3

Views: 1660

Answers (1)

ShivaGaire
ShivaGaire

Reputation: 2841

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

Upvotes: 1

Related Questions