Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PermissionError: [Errno 13] Permission denied on mac

When I try to run the code below, the mac refuse the connection.

from http.server import BaseHTTPRequestHandler, HTTPServer
class RequestHandler(BaseHTTPRequestHandler):
    def do_GET(self):
        message = "Welcome to COE 550!"
        self.protocol_version = "HTTP/1.1"
        self.send_response(200)
        self.send_header("Content-Length",len(message))
        self.end_headers()
        self.wfile.write(bytes(message, "utf8"))
        return

server = ('localhost', 80)
httpd = HTTPServer(server, RequestHandler)
httpd.serve_forever()

The output message is

PermissionError: [Errno 13] Permission denied

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The port 80 is considered as privileged port(TCP/IP port numbers below 1024) so the process using them must be owned by root. When you run a server as a test from a non-priviliged account, you have to test it on other ports, such as 2784, 5000, 8001 or 8080.

You could either run the python process as root or you have to use any non privileged port to fix this issue.

server = ('localhost', 8001)
httpd = HTTPServer(server, RequestHandler)
httpd.serve_forever()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading