python - 使用烧瓶时“权限被拒绝”
问题描述
我正在尝试使用 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)
谢谢!
解决方案
您收到该错误是因为您使用的是Privileged Port。
低于 1024 的 TCP/IP 端口号的特殊之处在于普通用户不允许在其上运行服务器。
...
当您从非特权帐户运行服务器作为测试时,您通常会在其他端口上测试它,例如 2784、5000、8001 或 8080。
例如,将您的端口更改为 5000,这将解决您的问题。
推荐阅读
- php - PHP:更好的算法来严格类型识别数组中的重复项
- wordpress - 发生错误,请重试或在 Elavon Converge 信用卡支付网关中尝试其他支付方式
- kotlin - Android Spinner 文字区别
- google-cloud-functions - 动作 SDK 不工作
- python - 多个条件 np.extract
- react-native - 键盘关闭时失去 TextInput 的焦点
- javascript - 如何在同一个 telnet 连接上发送多条数据?
- python - 如何在python中创建一个递归循环函数来循环遍历文件夹
- ios - 如何正确使用 Core Data managedObjectContext 以及保存上下文的正确方法?
- c# - 如何向 Autofac 注册实现多个接口的类型?