试图以访问权限禁止的方式访问套接字 (Bottle) (Python)

An attempt was made to access a socket in a way forbidden by its access permissions (Bottle) (Python)

我已经编写了这段代码,然后 运行 通过 CMD 编写了它。然而,当我 运行 代码发生时。

Bottle v0.12.18 server starting up (using WSGIRefServer())...
Listening on http://localhost:80/
Hit Ctrl-C to quit.

Traceback (most recent call last):
  File "bottle_01.py", line 7, in <module>
    run(host='localhost', port = 80, debug=True)
  File "C:\Users\Owner\Desktop\BottleWebApp\bottle.py", line 3137, in run
    server.run(app)
  File "C:\Users\Owner\Desktop\BottleWebApp\bottle.py", line 2789, in run
    srv = make_server(self.host, self.port, app, server_cls, handler_cls)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\wsgiref\simple_server.py", line 154, in make_server
    server = server_class((host, port), handler_class)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\socketserver.py", line 452, in __init__
    self.server_bind()
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\wsgiref\simple_server.py", line 50, in server_bind
    HTTPServer.server_bind(self)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\http\server.py", line 138, in server_bind
    socketserver.TCPServer.server_bind(self)
  File "C:\Users\Owner\AppData\Local\Programs\Python\Python38-32\lib\socketserver.py", line 466, in server_bind
    self.socket.bind(self.server_address)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

现在我问了我的教授,但他自己也不熟悉这个问题。我搜索了 Whosebug 并尝试禁用我的防火墙,但这似乎没有帮助。有什么建议么?这可能是一个管理问题?我的原始代码如下。

from bottle import route, run, static_file

@route('/')

def index():
    return static_file('webpage_01.html' , root= 'C:/Users/Owner/Desktop/BottleWebApp')
run(host='localhost', port = 80, debug=True)

当您尝试端口 8000 而不是 80 时,此问题是否消失?

您正在尝试绑定到端口 80。我不知道 Windows,但是在 Linux 上您的代码会失败,因为端口 80(就像 1024 以下的所有端口一样)是有特权的- - 只有 root 可以绑定到它们。这就是为什么您会看到大多数教程和 Web 框架默认使用高端口号,通常是 80008080.

参考文献:

https://www.w3.org/Daemon/User/Installation/PrivilegedPorts.html

https://en.wikipedia.org/wiki/Registered_port