1

I am following the Udacity course here: https://classroom.udacity.com/courses/ud388/lessons/4628431284/concepts/53174719510923

I am trying to run their python program using Flask. I started vagrant with vagrant ssh

I then tried to run that python file by typing python api_server.py. But when I go to http://0.0.0.0:5000/ on my browser, I get:

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again. 

Then I tried typing curl 'http://127.0.0.1:5000' in vagrant but got the error

vagrant@vagrant-ubuntu-trusty-32:~$ curl 'http://127.0.0.1:5000'
curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused

The api_server.py file is below:

#THIS IS A WEBSERVER FOR DEMONSTRATING THE TYPES OF RESPONSES WE SEE FROM AN API ENDPOINT
from flask import Flask
app = Flask(__name__)

#GET REQUEST

@app.route('/readHello')
def getRequestHello():
    return "Hi, I got your GET Request!"

#POST REQUEST
@app.route('/createHello', methods = ['POST'])
def postRequestHello():
    return "I see you sent a POST message :-)"
#UPDATE REQUEST
@app.route('/updateHello', methods = ['PUT'])
def updateRequestHello():
    return "Sending Hello on an PUT request!"

#DELETE REQUEST
@app.route('/deleteHello', methods = ['DELETE'])
def deleteRequestHello():
    return "Deleting your hard drive.....haha just kidding! I received a     DELETE request!"

if __name__ == '__main__':
    app.debug = True
    app.run(host='0.0.0.0', port=5000)  
user5739619
  • 217
  • 1
  • 6
  • 11
  • Make sure you do curl on the machine you are running their server script on. Moreover, use the exact same address and port as the python script is reporting. If still fails, just follow the minimal example of [flask](http://flask.pocoo.org/docs/0.10/quickstart/) – Jeroen Sep 13 '16 at 08:31
  • Does port 5000 is open in your firewall. – pa4080 Sep 13 '16 at 08:36

1 Answers1

0

In case you are running on Docker and if you are trying to connect from another docker console, make sure you are using "Docker exec" to attach the process to test the service. I was trying to connect with "docker run" which was creating another instance of docker and curl was giving me "connection refused" for 127.0.0.1:5000.