【问题标题】:An attempt was made to access a socket in a way forbidden by its access permissions (Bottle) (Python)试图以访问权限禁止的方式访问套接字 (Bottle) (Python)
【发布时间】:2020-11-18 20:35:38
【问题描述】:

我已经编写了这段代码,然后通过 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

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

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)

【问题讨论】:

    标签: python routes bottle


    【解决方案1】:

    当您尝试使用端口 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

    【讨论】:

    • 哇,非常感谢。这行得通。我的教授正在推动我们使用 80,但我会让他知道这可以在我的电脑上运行。我不知道端口是问题所在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 1970-01-01
    • 1970-01-01
    • 2011-02-16
    相关资源
    最近更新 更多