2
votes

I copy pasted the flask's 'hello world' app from their website and am trying to run it. I get an error message in Chrome saying

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Here is the 'hello world' app straight from flasks website

from flask import Flask
app = Flask(__name__)

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

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

What I have tried:

-temporarily disabling Avast!

-disabling windows firewall

-ensuring that the flask module is installed

This was working a couple days ago actually...

7
This was working a couple days ago actually. Yes, the code works. The error you see is not produced by Flask.Martijn Pieters♦
Yeah I know the code is fine, its worked for thousands of newbies before me :). I am wondering what could be preventing it from doing its thing.Kristifer Szabo
So what are URL are you using in your browser? You'll probably see the exact same error when you are not running the Flask script. Something else is running there, and it is not working.Martijn Pieters♦
Is there any sort of error message produced in the console in which you run hello.py?Robᵩ

7 Answers

6
votes

I don't know why but when I change

app.run()

to

app.run(port=4996)

it starts working. No idea why the default port is throwing an error. Oh well.

3
votes

For Windows machines you can use the command in cmd:

set FLASK_APP=python_file.py
flask run
2
votes
from flask import Flask

app = Flask(__name__)


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


if __name__ == '__name__':
    app.run()

app.run(port=5000)
1
votes

Some other process is running on port 5000. It may be you still have an old Flask process running, with broken code. Or a different web server altogether is running on that port. Shut down that process, or run on a different port.

You can switch to using a different port with the port argument to app.run():

app.run(port=8080)

If you can't figure out what process is still bound to port 5000, use the Windows Resource Monitor or run netstat -a -b from a command line. See How can you find out which process is listening on a port on Windows?

1
votes

I think you are trying to copy the route generated through your flask program in cmd by pressing ctrl+c which quits your running flask program . i was also doing the same.just try to type the route generated by your flask program on your browser . it will definitely resolve your problem.

0
votes

Where your python file store is, use cmd and then go on your file store directory, then

set FLASK_APP=filename.py

After this your flask run cmd will work.

0
votes
   from flask import Flask
   app = Flask(__name__) # creating app
   @app.route('/', methods['GET']) #routing it to the home page
   def home(): #function
       return "hello world"
   app.run(port=5000, debug=true) #function call by the app

Add port and use methods whatever your need is USE GET in your case and try to remove your cache and run the this code it will definitely work.