App.py is not running | DevOps Prerequisite Deploy Flask App

Hi, I am having trouble clearing the question 6:

Change port in app.py to 5000 and start the app.

I have used the commands in the hint and also checked some related threads posted by other people but still cannot understand what I am doing wrong.
sudo sed -i 's/8080/5000/g' app.py; python app.py

Here is the log I got. In the snippet below, I am using python3 command. The logs had no difference between using python3 and python.

thor@host01 /opt/simple-webapp-flask$ python3 app.py 
 * Serving Flask app 'app' (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
^CTraceback (most recent call last):
  File "app.py", line 14, in <module>
    app.run(host="0.0.0.0", port=5000)
  File "/home/thor/.local/lib/python3.6/site-packages/flask/app.py", line 920, in run
    run_simple(t.cast(str, host), port, self, **options)
  File "/home/thor/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 1017, in run_simple
    inner()
  File "/home/thor/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 966, in inner
    fd=fd,
  File "/home/thor/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 790, in make_server
    host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
  File "/home/thor/.local/lib/python3.6/site-packages/werkzeug/serving.py", line 693, in __init__
    super().__init__(server_address, handler)  # type: ignore
  File "/usr/lib64/python3.6/socketserver.py", line 456, in __init__
    self.server_bind()
  File "/usr/lib64/python3.6/http/server.py", line 138, in server_bind
    self.server_name = socket.getfqdn(host)
  File "/usr/lib64/python3.6/socket.py", line 673, in getfqdn
    hostname, aliases, ipaddrs = gethostbyaddr(name)
KeyboardInterrupt

Here is app.py

import os
from flask import Flask
app = Flask(__name__)

@app.route("/")
def main():
    return "Welcome!"

@app.route('/how are you')
def hello():
    return 'I am good, how about you?'

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)

Can someone give me a hand to solve this?

When I checked this task it did not validate if you run python3 app.py - try python app.py

1 Like

Thank you! it worked.