c3cris
c3cris

Reputation: 1326

PermissionError: [Errno 13] Permission denied Flask.run()

I am running MacOS X with python 3. The folder and files have 755 but I have also tested it in 777 with no luck. My question is if I have the right permissions why does it not let me run without sudo. Or are my settings incorrect?

cris-mbp:ProjectFolder cris$ python3 zbo.py 
Traceback (most recent call last):
  File "zbo.py", line 9, in <module>
    app.run(host="127.0.0.1",port=81,debug=True)
  File "/usr/local/lib/python3.5/site-packages/flask/app.py", line 843, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python3.5/site-packages/werkzeug/serving.py", line 677, in run_simple
    s.bind((hostname, port))
PermissionError: [Errno 13] Permission denied
cris-mbp:ProjectFolder cris$ sudo python3 zbo.py 
 * Running on http://127.0.0.1:81/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 106-133-233

Upvotes: 36

Views: 81486

Answers (4)

ajskateboarder
ajskateboarder

Reputation: 497

Hopefully, this is an OK answer, but you can get around this problem by running Flask as a super-user. Like this:

sudo python3 app.py

Or in Windows, just run PowerShell or Command Prompt as administrator and call Python normally.

Upvotes: 0

harish
harish

Reputation: 11

go to c:\python27\ directory and rigtlcick python.exe and tab to compaitbility and select the admin privilege option and apply the changes. Now you issue the command it allows to create the socket connection.after that run script using python

Upvotes: 0

Matt Healy
Matt Healy

Reputation: 18531

You're trying to run the app on a privileged port (81) - if you use a higher port such as 5000 you won't need sudo privileges.

Upvotes: 86

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137477

The "permission denied" error is occurring on the bind call; this has nothing to do with directory permissions.

You're attempting to bind to port 81 (an odd choice), which is a privileged port (one that is less than 1024). This means you need to run it as root.

Upvotes: 12

Related Questions