【问题标题】:"Permission denied" while using flask使用烧瓶时“权限被拒绝”
【发布时间】:2020-05-24 21:43:10
【问题描述】:

我正在尝试使用 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)

谢谢!

【问题讨论】:

标签: python flask


【解决方案1】:

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

1024以下的TCP/IP端口号是特殊的,普通用户 不允许在其上运行服务器。

...

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

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

【讨论】:

  • 如果我仍然想在特权端口上运行它怎么办?我尝试使用 sudo,但现在出现以下错误: Traceback(最近一次调用最后一次):文件“app.py”,第 2 行,在 from flask import Flask,render_template,request,redirect,flash,send_file ModuleNotFoundError : 没有名为“flask”的模块
  • @xkcd 你在系统级别安装了烧瓶吗? (sudo pip install ...)
  • 不,仅在 venv ... 我的印象是执行 sudo pip install 是个坏主意:$
  • @xkcd 使用特权端口也是个坏主意
  • 是的,我猜它和 sudo 基本一样 :) ...谢谢。
猜你喜欢
  • 2018-07-22
  • 1970-01-01
  • 1970-01-01
  • 2017-11-01
  • 2014-10-01
  • 2020-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多