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

标签 linux python-3.x flask vagrant

我在基于 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/

相关文章:

linux - 将内核模块添加到 Debian

linux - 自动化 Ubuntu 构建(或任何 Linux 发行版)

linux - 使用 nodebox 作为 python 3.5 的模块

python - 即使在 plt.plot 之前使用 plt.figure () 也会出现错误 <Figure size 1000x600 with 1 Axes>

python - chr() 等效返回一个字节对象,在 py3k

linux - 最快统计目录(包括子目录)文件数的方法

c++ - Linux _SC_PHYS_PAGES 在 Mac OS X 上不工作

javascript - 使用flask和render_template选项无法获取所需的html页面

python - 如何让 Flask-SQLAlchemy 与应用程序工厂模式一起工作

python - FlaskApp Running with Apache unable to save file on server side cannot get permission to work?