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












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)









share|improve this question

























  • 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

    – Jeroen
    Sep 13 '16 at 8:31











  • Does port 5000 is open in your firewall.

    – pa4080
    Sep 13 '16 at 8:36
















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)









share|improve this question

























  • 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

    – Jeroen
    Sep 13 '16 at 8:31











  • Does port 5000 is open in your firewall.

    – pa4080
    Sep 13 '16 at 8:36














1












1








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)









share|improve this question
















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)






python curl flask






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 13 '16 at 18:14







user5739619

















asked Sep 13 '16 at 7:42









user5739619user5739619

14139




14139













  • 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

    – Jeroen
    Sep 13 '16 at 8:31











  • Does port 5000 is open in your firewall.

    – pa4080
    Sep 13 '16 at 8:36



















  • 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

    – Jeroen
    Sep 13 '16 at 8:31











  • Does port 5000 is open in your firewall.

    – pa4080
    Sep 13 '16 at 8:36

















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

– Jeroen
Sep 13 '16 at 8:31





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

– Jeroen
Sep 13 '16 at 8:31













Does port 5000 is open in your firewall.

– pa4080
Sep 13 '16 at 8:36





Does port 5000 is open in your firewall.

– pa4080
Sep 13 '16 at 8:36










1 Answer
1






active

oldest

votes


















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.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f824306%2fcurl-7-failed-to-connect-to-127-0-0-1-port-5000-connection-refused-when-usin%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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.






    share|improve this answer




























      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.






      share|improve this answer


























        0












        0








        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 3 '18 at 13:42









        www.shipshuk.comwww.shipshuk.com

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f824306%2fcurl-7-failed-to-connect-to-127-0-0-1-port-5000-connection-refused-when-usin%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Human spaceflight

            Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

            File:DeusFollowingSea.jpg