1

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...

Kristifer Szabo
  • 429
  • 2
  • 7
  • 15
  • 4
    *This was working a couple days ago actually*. Yes, the code works. The error you see is *not produced by Flask*. – Martijn Pieters Mar 05 '16 at 19:22
  • 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 Mar 05 '16 at 19:24
  • 1
    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 Mar 05 '16 at 19:26
  • Is there any sort of error message produced in the console in which you run hello.py? – Robᵩ Mar 05 '16 at 19:26

7 Answers7

6

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.

Kristifer Szabo
  • 429
  • 2
  • 7
  • 15
  • 3
    That's because, as I already stated on your question, there is a **different** server running on the other port. – Martijn Pieters Mar 05 '16 at 19:31
  • 1
    @MartijnPieters Your right, I am new to this and didn't really understand your comment. But your right, even after changing to 4996, 5000 has an error. Thanks! – Kristifer Szabo Mar 05 '16 at 19:43
3

For Windows machines you can use the command in cmd:

set FLASK_APP=python_file.py
flask run
Employee
  • 2,434
  • 3
  • 22
  • 42
2
from flask import Flask

app = Flask(__name__)


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


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

app.run(port=5000)
Gehan Fernando
  • 942
  • 9
  • 21
1

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?

Community
  • 1
  • 1
Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
1

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

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.

Greenonline
  • 1,231
  • 6
  • 19
  • 25
0
   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.

yuviscor
  • 1
  • 1