gpt4 book ai didi

linux - 权限错误权限在简单的基本 Flask 应用程序中被拒绝

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:14:19 25 4
gpt4 key购买 nike

我在基于 vagrant 的 Linux 系统上运行这个脚本,这是运行 flask 应用程序的简单基本代码,我收到了这个错误:

raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

这是脚本:

#!/usr/bin python3

from flask import Flask
app = Flask(__name__)

@app.route('/')
@app.route('/hello')
def helloworld():
return 'Hello and Welcome to flask'

if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=5000)

我得到的错误:

vagrant@vagrant:/vagrant$ python3 project.py
* Serving Flask app "project" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
Traceback (most recent call last):
File "project.py", line 14, in <module>
app.run(host='0.0.0.0', port=5000)
File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 943, in run run_simple(host, port, self, **options)
File "/usr/local/lib/python3.5/dist-packages/werkzeug/serving.py", line 988, in run_simple
run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
File "/usr/local/lib/python3.5/dist-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
sys.exit(reloader.restart_with_reloader())
File "/usr/local/lib/python3.5/dist-packages/werkzeug/_reloader.py", line 176, in restart_with_reloader
exit_code = subprocess.call(args, env=new_environ, close_fds=False)
File "/usr/lib/python3.5/subprocess.py", line 557, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

最佳答案

我遇到了同样的问题,原来端口需要大于5000:

from flask import Flask, request, abort, jsonify

app = Flask(__name__)


@app.route('/getSquare', methods=['POST'])
def get_square():
pass

return jsonify({'answer': num ** 2})


if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001, debug=True) # make sure port is > 5000

关于linux - 权限错误权限在简单的基本 Flask 应用程序中被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55549964/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com