首页 > 解决方案 > 使用烧瓶时“权限被拒绝”

问题描述

我正在尝试使用 Wit.ai 制作一个信使机器人。为此,我需要一个 webhook。我正在使用 ngrok,这只是一个测试文件,但我收到了这个错误。

这是我得到的错误。

 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
Traceback (most recent call last):
  File "app.py", line 56, in <module>
    app.run(debug = True, port = 80)
  File "/home/parth/.local/lib/python3.6/site-packages/flask/app.py", line 990, in run
    run_simple(host, port, self, **options)
  File "/usr/local/lib/python3.6/dist-packages/werkzeug/serving.py", line 988, in run_simple
    s.bind(server_address)
PermissionError: [Errno 13] Permission denied

这是代码

import os, sys
from flask import Flask, request

app = Flask(__name__)
@app.route('/', methods=['GET'])
def verify():
    # Webhook verification
    if request.args.get("hub.mode") == "subscribe" and request.args.get("hub.challenge"):
        if not request.args.get("hub.verify_token") == "hello":
            return "Verification token mismatch", 403
        return request.args["hub.challenge"], 200
    return "Hello world", 200


if __name__ == "__main__":
    app.run(debug = True, port = 80)

谢谢!

标签: pythonflask

解决方案


您收到该错误是因为您使用的是Privileged Port

低于 1024 的 TCP/IP 端口号的特殊之处在于普通用户不允许在其上运行服务器。

...

当您从非特权帐户运行服务器作为测试时,您通常会在其他端口上测试它,例如 2784、5000、8001 或 8080。

例如,将您的端口更改为 5000,这将解决您的问题。


推荐阅读