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

Question:

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
Asked By: c3cris

||

Answers:

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.

Answered By: Jonathon Reinhart

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.

Answered By: Matt Healy

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

Answered By: harish

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.

Answered By: ajskateboarder
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.