0

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

  • The PermissionError: [errno 13] permission denied error occurs when you try to access a file from Python without having the necessary permissions. See this question: https://stackoverflow.com/questions/36434764/permissionerror-errno-13-permission-denied – Umar Yusuf Nov 04 '21 at 07:05

1 Answers1

0

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()
Abdul Niyas P M
  • 18,035
  • 2
  • 25
  • 46